# Running a single test script

**URL:** <https://discourse.julialang.org/t/running-a-single-test-script/136623>\
**Category:** General Usage\
**Tags:** question, package, testing\
**Created:** [April 8, 2026, 2:44pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623 "2026-04-08T14:44:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 8, 2026, 2:44pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/1 "2026-04-08T14:44:21Z")

</div>

I want to be able to run a single test just by including it. For example, imagine the following test file:

```julia
using Test, BenchmarkTools

@test 1+1 == 2

```

If I include it directly, it fails:

```julia
include("test/test_example.jl"
ERROR: LoadError: ArgumentError: Package BenchmarkTools not found in current path.
- Run 'import Pkg; Pkg.add("BenchmarkTools")' to install the BenchmarkTools package.
Stacktrace:

```

Now I modified it:

```julia-auto
using Pkg

Pkg.activate(@ __DIR__ )

using Test, BenchmarkTools

@test 1+1 == 2

```

And it works:

```julia
julia> include("test/test_example.jl")
  Activating project at '~/repos/SymbolicAWEModels.jl/test'
Test Passed

```

But Github Copilot tells me this would be a problematic approach:

```julia-auto
`Pkg.activate(@ __DIR__ )` at top-level will override the temporary test environment that `Pkg.test()` sets up (used in CI via `julia-actions/julia-runtest`). That can change dependency resolution/version selection mid-test run and make CI behavior non-reproducible. Consider activating only when this file is executed directly (e.g., based on `PROGRAM_FILE`), or handle `--project=test` selection in the runner script instead and remove per-file activation during `Pkg.test()` runs.

```

Is this approach problematic, or can I ignore this warning?

And why is the temporary test environment different from the environment in the test folder?

I use the workspace feature:

```julia-auto
[workspace]

projects = ["docs", "examples", "scripts", "test"]

```

and have a separate `Project.toml` file in the test folder, which - for example - contains `BenchmarkTools.jl`.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 8, 2026, 3:09pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/2 "2026-04-08T15:09:14Z")

</div>

With the workspace setup you can just start Julia with

```julia-auto
julia --project=test

```

and then include your test file.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 8, 2026, 3:10pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/3 "2026-04-08T15:10:54Z")

</div>

I know that, but I want to stay in the REPL as long as possible and want to be able to run single tests by just including the test file. I do the same with the examples in the example folder. I also want to be able to run them without having to activate the examples project explicitly.

Furthermore, I am using a custom system image, and then the command you shared would not be sufficient.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 8, 2026, 3:19pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/4 "2026-04-08T15:19:29Z")

</div>

In that case you can proceed like you started with `Pkg.activate(@ __DIR__ )` in every file. You can safely ignore CoPilot’s advice, it’s only relevant if you’re using the old approach with

```julia-auto
[targets]
test = [...]

```

in `Project.toml`.

---

<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:** [April 8, 2026, 3:33pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/5 "2026-04-08T15:33:22Z")

</div>

`TestEnv.activate()` is the universal way to activate test environemnt – always works.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 8, 2026, 4:20pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/6 "2026-04-08T16:20:03Z")

</div>

But that requires the package `TestEnv` to be installed. And it is usually broken for Julia versions that are not yet released.

I use now:

```julia-auto
using Pkg
if abspath(PROGRAM_FILE) == abspath(@ __FILE__ )
    Pkg.activate(@ __DIR__ )
end

```

to make Copilot happy.

And my CI tests pass now. Without this guard, one test failed on Julia 1.11.

---

<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:** [April 8, 2026, 5:33pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/7 "2026-04-08T17:33:02Z")

</div>

> [@ufechner7](#):
>
> But that requires the package `TestEnv` to be installed. And it is usually broken for Julia versions that are not yet released.

Indeed, I assumed released Julia versions, not some preliminary ones – didn’t know TestEnv doesn’t work on pre-versions.

Hmm, does this mean there is no universal way to properly activate test environment in Julia, something that would work all the way from LTS to pre-releases?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [April 8, 2026, 5:39pm UTC](https://discourse.julialang.org/t/running-a-single-test-script/136623/8 "2026-04-08T17:39:15Z")

</div>

> [@aplavin](#):
>
> Hmm, does this mean there is no universal way to properly activate test environment in Julia, something that would work all the way from LTS to pre-releases?

I used to use TestEnv a lot, but the sub-projects available since Julia 1.12 are better. So I am switching away from TestEnv. I need multiple separate sub-projects, for testing, examples, docs etc.

And the approach above works good enough for me.
