How to use workspaces to test?

I’m writing a program and I’d like to add tests. I search the web and find that there’s a new way:

The recommended way to add test-specific dependencies is to use workspaces. This is done by:

  1. Adding a [workspace] section to your package’s Project.toml:
[workspace]
projects = ["test"]

Then what? Having done that, how do I add a test-specific dependency to the workspace? Do I make a test subdirectory? Are workspaces available starting in 1.12 (which I’m running) or 1.13 (which doesn’t exist yet, according to juliaup)?

2 Likes

Workspaces are available in 1.12.

This is a good template to follow: GitHub - JuliaBesties/BestieTemplate.jl: Template for Julia Programming Language packages using the copier engine.

As you can see there is a test folder with its own Project.toml. Then there is a runtests.jl which discovers all the tests which you can just copy.

(the template doesn’t use workspaces yet, but I did create an issue for it: Usage of `[workspace]` section in `Project.toml` · Issue #559 · JuliaBesties/BestieTemplate.jl · GitHub, this doesn’t matter for the test folder itself)

This looks like a neat feature but restricted to 1.12+, will it be back ported to lts ? Otherwise, can I still use it if my package supports current lts or do I have to wait ?

New features are not backported to earlier versions, lts or not.

2 Likes

I know the old way, but this is a new project and I just found out there’s a new way. What’s the new way?

If in Project.toml I create a workspace called test, how do I configure a workspace?

Each project in a workspace can include their own dependencies, compatibility information, and even function as full packages.

How do I put these three things into a workspace? I don’t see an explanation or example.

That part hasn’t changed if I understand correctly. Your folder test is the workspace.

Do I still need to put a Project.toml in test?

I added a single spot-check test and got it to pass, using a workspace. Can you check if I’m doing it right?

Looks okay to me!