# Pkg \`target\` based test specific dependencies just doesn't work?

**URL:** <https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965>\
**Category:** New to Julia\
**Created:** [April 11, 2025, 8:57am UTC](https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965 "2025-04-11T08:57:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Hill](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter_hill/32/216260_2.png) [@Peter\_Hill](https://discourse.julialang.org/u/Peter_Hill)\
**Post date:** [April 11, 2025, 8:57am UTC](https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965/1 "2025-04-11T08:57:53Z")

</div>

I’m very new to Julia, and I’ve been trying to get some unit tests up with TestItemRunner.jl. Following the recommended way to specify test dependencies (my account is too new to link, but this is following the Pkg.jl docs):

`Project.toml`:

```toml
name = "mvce"
uuid = "5c5c69df-07ce-4eec-9db9-de18ccd496a9"
authors = ["Peter Hill <peter.hill@york.ac.uk>"]
version = "0.1.0"

[extras]
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[targets]
test = ["TestItems", "TestItemRunner"]

```

and `test/runtests.jl`

```julia
using TestItemRunner

```

and running from the command line:

```console
$ julia --project=. test/runtests.jl
ERROR: LoadError: ArgumentError: Package TestItemRunner not found in current path.
- Run `import Pkg; Pkg.add("TestItemRunner")` to install the TestItemRunner package.

```

If I instead use the alternative, possibly unstable `test/Project.toml` method:

`Project.toml`:

```toml
name = "mvce"
uuid = "5c5c69df-07ce-4eec-9db9-de18ccd496a9"
authors = ["Peter Hill <peter.hill@york.ac.uk>"]
version = "0.1.0"

```

`test/Project.toml`:

```toml
[dep]
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

```

Then after activating the project and test environments and instantiating inside the REPL, I can run:

```console
$ julia --project=test test/runtests.jl

```

which works.

What am I missing? Does the `target` based approach just not work? Have I missed a step? Is the `test/Project.toml` the recommended way?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 11, 2025, 9:00am UTC](https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965/2 "2025-04-11T09:00:33Z")

</div>

The `[targets]` approach is (as far as I’m aware) only compatible with using `]test` in the REPL (or explicitly calling the `Pkg.test` API). If you want to run your tests as a standalone “script”, using a dedicated test Project is the best approach.

---

<div class="post-metadata">

**Author:** ![Peter\_Hill](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter_hill/32/216260_2.png) [@Peter\_Hill](https://discourse.julialang.org/u/Peter_Hill)\
**Post date:** [April 11, 2025, 9:15am UTC](https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965/3 "2025-04-11T09:15:10Z")

</div>

Thanks, that does indeed work! That is not at all clear from the docs, so I will make an issue on Pkg.jl

---

<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:** [April 11, 2025, 4:00pm UTC](https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965/4 "2025-04-11T16:00:49Z")

</div>

One other way is to use TestEnv.jl to create the test environment. That works with the targets approach, and allows rerunning tests in the same Julia session (unlike `Pkg.test` which starts a separate process).

---

<div class="post-metadata">

**Author:** ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)\
**Post date:** [April 11, 2025, 4:48pm UTC](https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965/5 "2025-04-11T16:48:57Z")

</div>

There’s an open issue for adding support for Pkg to activate these environments without the need for TestEnv.jl here [TestEnv.jl functionality/support · Issue #3460 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/3460)

Something like this might be a good design:

```julia
pkg> activate Foo --target test

```

or

```julia
pkg> activate Foo --target build

```

which is what `Pkg.build` uses, if present.

There is a function that might do most of the work already here

> <https://github.com/JuliaLang/Pkg.jl/blob/d4bd714428dc352e3f550b2e3dc079d6bb62e530/src/Operations.jl#L2218>

---

<div class="post-metadata">

**Author:** ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)\
**Post date:** [April 11, 2025, 6:20pm UTC](https://discourse.julialang.org/t/pkg-target-based-test-specific-dependencies-just-doesnt-work/127965/6 "2025-04-11T18:20:47Z")

</div>

I started implementing it here [Add ability to activate test/build target envs by IanButterworth · Pull Request #4218 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/pull/4218)
