# How can you build the test executable in dune without running the executable

**URL:** <https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386>\
**Category:** Ecosystem\
**Tags:** dune\
**Created:** [February 21, 2019, 1:24am UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386 "2019-02-21T01:24:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnWu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/johnwu/32/1351_2.png) [@JohnWu](https://discuss.ocaml.org/u/JohnWu)\
**Post date:** [February 21, 2019, 1:24am UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386/1 "2019-02-21T01:24:18Z")

</div>

I know `dune run` runs builds the inline test runner executable for tests and runs them. However, I just want to run the tests. How can I just get the executable for the test? Also, I tried running `dune build` to build the tests, but it does not produce the executable.

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [February 21, 2019, 1:46am UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386/2 "2019-02-21T01:46:58Z")

</div>

As far as I know, dune does incremental builds, so if the test executable is already built, it will not rebuild it. But maybe somebody should confirm this!

---

<div class="post-metadata">

**Author:** ![rgrinberg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rgrinberg/32/40_2.png) [@rgrinberg](https://discuss.ocaml.org/u/rgrinberg)\
**Post date:** [February 21, 2019, 6:13am UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386/3 "2019-02-21T06:13:01Z")

</div>

Yeah, there’s no need to optimize for this manually. Dune should do the minimum amount of work to run your tests if you’ve specified your dependencies precisely.

But in case, you still need to do this, you can do:

```auto
$ dune exec --no-build ./path/to/test.exe

```

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [February 21, 2019, 6:53am UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386/4 "2019-02-21T06:53:29Z")

</div>

I think he was looking for:

```auto
dune build ./src/test.exe

```

---

<div class="post-metadata">

**Author:** ![rdavison](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rdavison/32/4321_2.png) [@rdavison](https://discuss.ocaml.org/u/rdavison)\
**Post date:** [February 21, 2019, 7:02am UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386/5 "2019-02-21T07:02:59Z")

</div>

While we’re on the subject, is there a way of doing the same thing for inline tests?

---

<div class="post-metadata">

**Author:** ![jeremiedimino](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jeremiedimino/32/699_2.png) [@jeremiedimino](https://discuss.ocaml.org/u/jeremiedimino)\
**Post date:** [February 21, 2019, 1:21pm UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386/6 "2019-02-21T13:21:49Z")

</div>

You can but the name of the executable is a bit more complicated, we generate it in a `.<something>` sub-directory. If you run dune with `--verbose`, or look in the `_build/log`, you can see the exact command that is being run.

---

<div class="post-metadata">

**Author:** ![JohnWu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/johnwu/32/1351_2.png) [@JohnWu](https://discuss.ocaml.org/u/JohnWu)\
**Post date:** [February 21, 2019, 6:38pm UTC](https://discuss.ocaml.org/t/how-can-you-build-the-test-executable-in-dune-without-running-the-executable/3386/7 "2019-02-21T18:38:34Z")

</div>

Thanks guys. I was able to build the test runner executable without running the test. As a result, I was able to make a script in OCaml that runs an individual test in a file without running an entire test for a library. I made this script because I was not able to find a command in dune that does this.

Come check out the script here:

> <https://gist.github.com/johnwu93/8a190cce2a1dbfb4f120ca01738d39be>
