# Add Test as a dependency of project

**URL:** https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043
**Category:** General Usage
**Tags:** testing, pkg
**Created:** [October 21, 2022, 12:55am UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043 "2022-10-21T00:55:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![HashBrown](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hashbrown/32/43601_2.png) [@HashBrown](https://discourse.julialang.org/u/HashBrown)
#### Post date: [October 21, 2022, 12:55am UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043/1 "2022-10-21T00:55:01Z")

</div>

So I have a simple and small project that is completely standalone and doesn’t use anything outside of the standard library. The only thing in the standard library that I use is `Test` for my test suite which is located at `test/runtests.jl`

I can run the test suite from the root of the project using the command `julia --project=. test/runtests.jl` and everything runs fine.

However if I run `julia --project=.` and then press `]` to go to `Pkg`. And then run `test` I get a failure saying

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

```

Both of these are in the same environment so I am confused why this is happening. Also don’t know if this is relevant but I don’t have any packages installed in the global Julia environment. That is if I don’t specify a project, then go to `Pkg`, and type `status` it is empty.

If I `add Test` both ways of running the test suite work. But I would like to understand the discrepancy for future reference.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [October 21, 2022, 1:01am UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043/2 "2022-10-21T01:01:38Z")

</div>

```julia
...
[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

```

---

<div class="post-metadata">

### Author: ![HashBrown](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hashbrown/32/43601_2.png) [@HashBrown](https://discourse.julialang.org/u/HashBrown)
#### Post date: [October 21, 2022, 2:43am UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043/3 "2022-10-21T02:43:05Z")

</div>

@jling I’m sorry could you elaborate more on how this explains the discrepancy I am seeing

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [October 21, 2022, 5:49am UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043/4 "2022-10-21T05:49:51Z")

</div>

When you run a test via Pkg, the tests are not run in the current project but instead a new project which additionally includes dependencies in the `extras.test` list in Project.toml.

So in most packages you put Test into this list but don’t include it in the main `deps` because the package itself doesn’t normally require it.

---

<div class="post-metadata">

### Author: ![HashBrown](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hashbrown/32/43601_2.png) [@HashBrown](https://discourse.julialang.org/u/HashBrown)
#### Post date: [October 21, 2022, 6:13am UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043/5 "2022-10-21T06:13:29Z")

</div>

@cjdoris why does it work when I don’t `add Test` and run it via the command line directly? I didn’t have `Test` in my project either when I ran that. That goes for all standard library packages. I can use them without adding them in `Pkg`.

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [October 21, 2022, 6:18am UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043/6 "2022-10-21T06:18:11Z")

</div>

When you run anything at the top level (eg a script or the REPL) you can use any package in the load path, which normally includes the current project, the global v1.8 project and all the stdlibs.

However when a package is imported it can only use whatever is listed in its Project.toml `deps` and when a package is tested it can use only it’s Project.toml `deps` and `extras.test`.

---

<div class="post-metadata">

### Author: ![HashBrown](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hashbrown/32/43601_2.png) [@HashBrown](https://discourse.julialang.org/u/HashBrown)
#### Post date: [November 9, 2022, 4:46pm UTC](https://discourse.julialang.org/t/add-test-as-a-dependency-of-project/89043/7 "2022-11-09T16:46:16Z")

</div>

> When you run anything at the top level (eg a script or the REPL)

What other ways are there to run Julia? I.e how doest the `test` command run Julia in a way that only uses what is explicitly stated in our `Project.toml` file
