# Dependencies in \`./test/Project.toml\`

**URL:** <https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285>\
**Category:** Package Management\
**Tags:** question, package\
**Created:** [August 4, 2022, 8:15am UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285 "2022-08-04T08:15:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![this\_josh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/this_josh/32/42679_2.png) [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Post date:** [August 4, 2022, 8:15am UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285/1 "2022-08-04T08:15:55Z")

</div>

According to the [Pkg.jl docs](https://pkgdocs.julialang.org/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.2-and-above) for Julia versions \>1.2 it is recommended to create a test environment, `activate ./test`. Here, your package `foo` is automatically added and you can add relevant packages such as `Test.jl`. However, when I do this `foo`’s dependencies are not available in the test environment, e.g.:

```julia
     Testing Running tests...
ERROR: LoadError: ArgumentError: Package JuMP not found in current path.
- Run `import Pkg; Pkg.add("JuMP")` to install the JuMP package.

```

I’ve found that doing this

```nohighlight
] activate ./test
add JuMP

```

avoids the error above. But this causes duplication in dependency declarations. I imagine with this workflow it is also possible to test with incorrect versions and/or you could have extra packages in your test env allowing your tests to pass.

Is my usage of the test environment incorrect? If so, how should I be defining dependencies?

Also, I’ve seen a lot of established packages, such as [Flux.jl](https://github.com/FluxML/Flux.jl/blob/master/Project.toml) and [JuMP.jl](https://github.com/jump-dev/JuMP.jl/blob/master/Project.toml) are defining test packages under the `extras` section. Again, according to the [Pkg.jl docs](https://github.com/jump-dev/JuMP.jl/blob/master/Project.toml) this method is only suggested for Julia versions 1.0 and 1.1, which neither JuMP nor Flux support.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [August 4, 2022, 10:35am UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285/2 "2022-08-04T10:35:45Z")

</div>

> [@this\_josh](#):
>
> Also, I’ve seen a lot of established packages, such as [Flux.jl](https://github.com/FluxML/Flux.jl/blob/master/Project.toml) and [JuMP.jl](https://github.com/jump-dev/JuMP.jl/blob/master/Project.toml) are defining test packages under the `extras` section. Again, according to the [Pkg.jl docs](https://github.com/jump-dev/JuMP.jl/blob/master/Project.toml) this method is only suggested for Julia versions 1.0 and 1.1, which neither JuMP nor Flux support.

The test project approach has some issues so many packages don’t use it. Unfortunately the Pkg documentation is pretty misleading on this point. See e.g. [Clarify current fragility of `test/Project.toml` approach · Issue #1788 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/1788).

---

<div class="post-metadata">

**Author:** ![this\_josh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/this_josh/32/42679_2.png) [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Post date:** [August 4, 2022, 10:59am UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285/3 "2022-08-04T10:59:34Z")

</div>

I see, so should I use the `extras` method and ignore the suggest Julia versions?

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [August 4, 2022, 11:32am UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285/4 "2022-08-04T11:32:30Z")

</div>

Yeah, that’s what I do. It’s a bit annoying because you have to edit the extras section manually, but often I just do `] add MyTestDep` to get the UUID into the Project.toml under `[deps]`, and then I cut-and-paste it over to the `[extras]` section.

---

<div class="post-metadata">

**Author:** ![this\_josh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/this_josh/32/42679_2.png) [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Post date:** [August 4, 2022, 12:13pm UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285/5 "2022-08-04T12:13:55Z")

</div>

Okay, thank you this is what I’ll do.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [August 4, 2022, 1:58pm UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285/6 "2022-08-04T13:58:38Z")

</div>

I personally find the separate test Project.toml approach more convenient to use, and haven’t seen issues like the one referred to in @ericphanson’s link. Those issues probably only arise when you keep the Manifest.toml file stored together with the package, which isn’t really done anywhere often.

As for repeating common dependencies in two Project.toml files: this isn’t really complete duplication. For example, a package can support a wider range of package or julia versions than its tests. Then you just put corresponding different compats in those Project.toml files and everything works fine.  
And often you don’t need most of the package deps in the tests anyway, so duplication is minimal.

---

<div class="post-metadata">

**Author:** ![mmiller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmiller/32/20805_2.png) [@mmiller](https://discourse.julialang.org/u/mmiller)\
**Post date:** [August 4, 2022, 4:17pm UTC](https://discourse.julialang.org/t/dependencies-in-test-project-toml/85285/7 "2022-08-04T16:17:41Z")

</div>

[TestEnv.jl](https://github.com/JuliaTesting/TestEnv.jl) can also be used to load the test environment as it is in testing.
