# How can I load code to be able to test all of it?

**URL:** <https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351>\
**Category:** General\
**Created:** [August 22, 2026, 2:58am UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351 "2026-08-22T02:58:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Davidson](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@Greg\_Davidson](https://racket.discourse.group/u/Greg_Davidson)\
**Post date:** [August 22, 2026, 2:58am UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/1 "2026-08-22T02:58:42Z")

</div>

I'd like to test my code in `module.rkt` with tests in `module-test.rkt` and the **rackunit** documentation advises I use

> (require rackunit "module.rkt") in module-test.rkt

Alas, this only allows me to test things bound to symbols exported from `module.rkt` and I want to test everything..

Guessing, I looked up _load_ as an alternative and got lost in the explanation of _load-handlers_ and other things I didn't understand.

What, please, is the easy and accepted way to do what I'd like to do?

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [August 22, 2026, 3:46am UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/2 "2026-08-22T03:46:08Z")

</div>

1. A mix of `namespace-require` `module->namespace` `namespace-mapped-symbols` and `eval` can get you all of a module. That's dirty.

2. Consider using a submodule for testing instead. ([Modular Programming](https://felleisen.org/matthias/Thoughts/Modular_Programming.html)) might help.

---

<div class="post-metadata">

**Author:** ![Greg\_Davidson](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@Greg\_Davidson](https://racket.discourse.group/u/Greg_Davidson)\
**Post date:** [August 22, 2026, 3:59am UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/3 "2026-08-22T03:59:04Z")

</div>

I would like this low-level code testing individual procedures to exist outside of the tree of logical modules which comprise the system. Otherwise it totally bloats the files with low-level test code. I would like the _provide_ and _require_ forms to relate only to how the modules are expected to be used, so they'll work fine for integration tests, but not low-level tests. Am I missing something or is this a reasonable thing to want to do? Is there an easy and non-dirty way to achieve this? if not, I'll create a make rule to concatenate the the two files into a temporary file. Thanks for any suggestions on a non-kludgy way to achieve this!

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [August 22, 2026, 8:14am UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/4 "2026-08-22T08:14:53Z")

</div>

Look at `require/expose`.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [August 22, 2026, 1:38pm UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/5 "2026-08-22T13:38:08Z")

</div>

I suspect many (but not all!) Racketeers will not understand what you mean by « bloat », especially when the stated objective is (also) to access private module definitions.

So, a few options:

- only test the public interface. A frame challenge, but often that’s the only place where test failures are useful.
- Test the public interface in a separate test module and the private implementation in `(module+ test …)`.
- require/expose as mentioned elsewhere
- export the private definitions via a submodule that is used for testing, _e.g._ `(module+ for-tests (provide …))`. This becomes a public interface in the same way as, say, modules in a `foo/private` collection path—socially, we all agree it’s ok to break folks who have deliberately chosen to ignore the warning signs and reach into your guts anyway. (A bit like Python’s « we’re all adults » idea.)

HTH

---

<div class="post-metadata">

**Author:** ![jjsimpso](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jjsimpso/32/602_2.png) [@jjsimpso](https://racket.discourse.group/u/jjsimpso)\
**Post date:** [August 22, 2026, 2:41pm UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/6 "2026-08-22T14:41:07Z")

</div>

Is it possible to keep the `test` submodule in a separate file and bring it in with [include](https://docs.racket-lang.org/reference/include.html#%28form._%28%28lib._racket%2Finclude..rkt%29._include%29%29)? I have never used `include`, but if this works it would meet the goal of avoiding bloat in `module.rkt`.

---

<div class="post-metadata">

**Author:** ![Greg\_Davidson](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@Greg\_Davidson](https://racket.discourse.group/u/Greg_Davidson)\
**Post date:** [August 22, 2026, 8:13pm UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/7 "2026-08-22T20:13:26Z")

</div>

(include "module.txt") did it, much thanks!!!

---

<div class="post-metadata">

**Author:** ![Greg\_Davidson](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@Greg\_Davidson](https://racket.discourse.group/u/Greg_Davidson)\
**Post date:** [August 22, 2026, 8:28pm UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/8 "2026-08-22T20:28:39Z")

</div>

Thanks for all of the good ideas. By bloat I mean that the non-test code for all of the little procedures becomes obscured by the much larger amount of test code. This is not a problem for me as I use Emacs with Outshine-Mode (probably switching to outline-minor-mode soon) to hide/show what I want, but my students use DrRacket and get overwhelmed and stop reading the code.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [August 23, 2026, 12:44pm UTC](https://racket.discourse.group/t/how-can-i-load-code-to-be-able-to-test-all-of-it/4351/9 "2026-08-23T12:44:30Z")

</div>

If the test module includes the runtime module, you should know that struct definitions are generative. That is:

```scheme
(struct a () #:transparent)
(define a1 (a))
(struct a () #:transparent)
(define a2 (a))
(equal? a1 a2)

```

(_should_) yield false.

Structs permeate Racket in sometimes unexpected ways, and it can be strange to test computations involving the « same » struct from the included version of a module and the required form of a module, perhaps transitively. Debugging is even weirder, as I don’t think there’s an easy way to make it obvious the structs come from different places?

Anyway, I’d recommend against « tests `include` program », since you may then test a program with different semantics than the one you actually run.

What I think @jjsimpso recommended was for the program module to include a test module, which is the other way ‘round and could work nicely. The module to include starts `(module+ test` in my conception.
