# Interactive testing and test-specific dependencies

**URL:** <https://discourse.julialang.org/t/interactive-testing-and-test-specific-dependencies/76151>\
**Category:** General Usage\
**Tags:** question, testing, environment\
**Created:** [February 10, 2022, 9:30am UTC](https://discourse.julialang.org/t/interactive-testing-and-test-specific-dependencies/76151 "2022-02-10T09:30:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 10, 2022, 9:30am UTC](https://discourse.julialang.org/t/interactive-testing-and-test-specific-dependencies/76151/1 "2022-02-10T09:30:29Z")

</div>

I do not understand how [test-specific dependencies](https://pkgdocs.julialang.org/dev/creating-packages/#Test-specific-dependencies-in-Julia-1.2-and-above) are meant to be used in interactive work.

To make this concrete, suppose that package `Foo` has

```julia
using Foo
using Test
using Bar 

```

in `test/runtests.jl`. There is also a `test/Project.toml` that specifies `Test` and `Bar` as dependencies. Importantly, these are not dependencies of `Foo`.

`Pkg.test()` works fine when `Foo` is the active environment. However, it is occasionally useful to run tests interactively. Currently I

1. activate `Foo` (`] activate ..` with `test/` as the current directory), and evaluate `using Foo`. **Otherwise it is not found.**
2. then I `] activate .` the test directory, and evaluate the rest of the test code.

This is a bit cumbersome, so I must be missing something.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [February 10, 2022, 10:40am UTC](https://discourse.julialang.org/t/interactive-testing-and-test-specific-dependencies/76151/2 "2022-02-10T10:40:49Z")

</div>

The current situation is clearly sub-optimal and it would be really nice to fix [Pkg.jl#1233](https://github.com/JuliaLang/Pkg.jl/issues/1233).

* * *

With the setup you describe I would simply add `Foo` to `test/Project.toml` using a relative path. You would then have something like:

```julia
$ tree .
.
├── Manifest.toml
├── Project.toml
├── src
│ └── Foo.jl
└── test
    ├── Manifest.toml
    ├── Project.toml
    └── runtests.jl

2 directories, 6 files

$ pkg --project=test dev .
   Resolving package versions...
    Updating `/tmp/tmp.w9xxYUTzYF/Foo/test/Project.toml`
  [8722260b] + Foo v0.1.0 `..`
    Updating `/tmp/tmp.w9xxYUTzYF/Foo/test/Manifest.toml`
  [8722260b] + Foo v0.1.0 `..`

```

Note that I `dev`d with a relative path (`.`) and that the path for `Foo` in `test/Manifest.toml` is stored relative to the project (`..`).

Another way I often use is to simply add the test dependencies to the main project (but not committing it, obviously).

* * *

Edit: I forgot to mention the [`TestEnv.jl`](https://github.com/JuliaTesting/TestEnv.jl) package, which tries to mimic [Pkg.jl#1233](https://github.com/JuliaLang/Pkg.jl/issues/1233). I have not used this myself though.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 10, 2022, 1:02pm UTC](https://discourse.julialang.org/t/interactive-testing-and-test-specific-dependencies/76151/3 "2022-02-10T13:02:55Z")

</div>

> [@fredrikekre](#):
>
> Another way I often use is to simply add the test dependencies to the main project

What if they are added to `[extras]` of the main Project.toml? Are they installed when the package is installed? What at the drawbacks of this approach?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [February 10, 2022, 1:17pm UTC](https://discourse.julialang.org/t/interactive-testing-and-test-specific-dependencies/76151/4 "2022-02-10T13:17:29Z")

</div>

> [@lmiq](#):
>
> What if they are added to `[extras]` of the main Project.toml?

> [@lmiq](#):
>
> What at the drawbacks of this approach?

You can’t `using` them.

> Are they installed when the package is installed?

No.
