# Adding test-specific dependencies

**URL:** <https://discourse.julialang.org/t/adding-test-specific-dependencies/101100>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [July 3, 2023, 12:50am UTC](https://discourse.julialang.org/t/adding-test-specific-dependencies/101100 "2023-07-03T00:50:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 3, 2023, 12:50am UTC](https://discourse.julialang.org/t/adding-test-specific-dependencies/101100/1 "2023-07-03T00:50:50Z")

</div>

The [Pkg](https://pkgdocs.julialang.org/v1/creating-packages/#Test-specific-dependencies) documentation related to adding test-specific dependencies mentions the addition of the required packages under `[extras]` and `[target]` in the following way:

```julia
[extras]
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Markdown", "Test"]

```

The `add PackageName` method is adding the `PackageName` under the `[deps]` - and I am unaware of any documented way to add the test-specific dependencies straightforwardly.

I always copy-pasted from `[deps]` and manually added the package names to the `[targets]` in my `Project.toml` file.

I had no problem with this before, but it gets a little annoying when the number of test-related packages is larger.

Is there something that I am missing? Some material that documents this and I failed to discover? How are you doing this?

Specifically - is there some variation of `add PackageName` command that will place the added packages under `[extras]` (and hopefully add the entries to `[targets]` also)?

P.S. I prefer the single file approach (using `[targets]`) - without creating the `test/Project.toml` file.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [July 3, 2023, 2:08am UTC](https://discourse.julialang.org/t/adding-test-specific-dependencies/101100/2 "2023-07-03T02:08:36Z")

</div>

as far as i know, there isn’t any way to do this from the pkg prompt. it would be useful to allow this!

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 3, 2023, 7:19am UTC](https://discourse.julialang.org/t/adding-test-specific-dependencies/101100/3 "2023-07-03T07:19:15Z")

</div>

Unrelated but the docs seemed a bit incoherent there: [Clarify test dependencies paragraph by moving note about the "old" version by gdalle · Pull Request #3533 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/pull/3533)

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [July 3, 2023, 7:58am UTC](https://discourse.julialang.org/t/adding-test-specific-dependencies/101100/4 "2023-07-03T07:58:03Z")

</div>

When using a separate [`test/Project.toml`](https://pkgdocs.julialang.org/v1/creating-packages/#test/Project.toml-file-test-specific-dependencies) way of declaring test-only dependencies, then the tooling is a bit nicer, since you can simply use `Pkg.add` with the `test` environment active:

```julia
(MyProject) pkg> activate ./test
Activating project at `.../test`

(test) pkg> add SomeTestOnlyDependency
[...]

```

  

EDIT: sorry, I had not seen your PS

> [@algunion](#):
>
> P.S. I prefer the single file approach (using `[targets]`) - without creating the `test/Project.toml` file.

May I ask why? I personally tend to like the `test/Project.toml` approach more, precisely because of this tooling issue with the target-based approach.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 3, 2023, 8:46am UTC](https://discourse.julialang.org/t/adding-test-specific-dependencies/101100/5 "2023-07-03T08:46:10Z")

</div>

Because of:

- the fact that you might have to specify your own package’s dependencies twice, possibly with different compat bounds
- which gives rise to this bug ["cannot merge projects" error · Issue #1585 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/1585)

I think there are open issues / PRs to put every nonstandard dependency (test, docs, benchmarks, etc.) in the same spot (`Project.toml` with different targets) but I can’t remember where I saw them

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 3, 2023, 9:55am UTC](https://discourse.julialang.org/t/adding-test-specific-dependencies/101100/6 "2023-07-03T09:55:56Z")

</div>

It somewhat felt less work and more elegant to have things under `[extras]`/`[targets]`. But this is somewhat subjective - and I will not try to make up some articulate answer here.

However, after reading your answers, the `test/Project.toml` seems a better option - since I cannot have things going my way with the other approach.
