Adding test-specific dependencies

The Pkg documentation related to adding test-specific dependencies mentions the addition of the required packages under [extras] and [target] in the following way:

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

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.


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


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

1 Like

When using a separate test/Project.toml 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:

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

(test) pkg> add SomeTestOnlyDependency

EDIT: sorry, I had not seen your PS

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.


Because of:

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


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.