Skip to content

Commit 16cea78

Browse files
committed
Add multiple test explanation
1 parent b92a424 commit 16cea78

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

docs/side_quests/nf-test.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ Success! The pipeline runs successfully and the test passes. Now we have began t
406406

407407
## 1.4. Test the output
408408

409-
Let's add an assertion to our test to check the output file was created. We'll also update the test name again to reflect that we're now checking both process execution and output files.
409+
Let's add an assertion to our test to check the output file was created.
410+
411+
We can also add it as a separate test, with an informative name.
410412

411413
**Before:**
412414

@@ -441,6 +443,19 @@ Let's add an assertion to our test to check the output file was created. We'll a
441443
then {
442444
assert workflow.success
443445
assert workflow.trace.tasks().size() == 6
446+
}
447+
448+
}
449+
450+
test("Should produce correct output files") {
451+
452+
when {
453+
params {
454+
input_file = "${projectDir}/greetings.csv"
455+
}
456+
}
457+
458+
then {
444459
assert file("$launchDir/results/Bonjour-output.txt").exists()
445460
assert file("$launchDir/results/Hello-output.txt").exists()
446461
assert file("$launchDir/results/Holà-output.txt").exists()
@@ -468,13 +483,14 @@ https://www.nf-test.com
468483

469484
Test Workflow main.nf
470485

471-
Test [1d4aaf12] 'Should run successfully with correct processes and output files' PASSED (1.591s)
486+
Test [f0e08a68] 'Should run without failures' PASSED (8.144s)
487+
Test [d7e32a32] 'Should produce correct output files' PASSED (6.994s)
472488

473489

474-
SUCCESS: Executed 1 tests in 1.612s
490+
SUCCESS: Executed 2 tests in 15.165s
475491
```
476492

477-
Success! The test passes because the pipeline completed successfully, the correct number of processes ran and the output files were created.
493+
Success! The test passes because the pipeline completed successfully, the correct number of processes ran and the output files were created. This should also show you how useful it is to provide those informative names for your tests.
478494

479495
This is just the surface, we can keep writing assertions to check the details of the pipeline, but for now let's move on to testing the internals of the pipeline.
480496

@@ -1014,11 +1030,12 @@ Test Process convertToUpper
10141030

10151031
Test Workflow main.nf
10161032

1017-
Test [1d4aaf12] 'Should run successfully with correct processes and output files' PASSED (1.652s)
1033+
Test [f0e08a68] 'Should run without failures' PASSED (8.144s)
1034+
Test [d7e32a32] 'Should produce correct output files' PASSED (6.994s)
10181035

10191036
Test Process sayHello
10201037

1021-
Test [f91a1bcd] 'Should run without failures and produce correct output' PASSED (1.664s)
1038+
Test [f91a1bcd] 'Should run without failures and contain expected greeting' PASSED (1.664s)
10221039

10231040

10241041
SUCCESS: Executed 3 tests in 5.007s
@@ -1031,17 +1048,24 @@ Check that out! We ran 3 tests, 1 for each process and 1 for the whole pipeline
10311048
In this side quest, we've learned:
10321049

10331050
1. How to initialize nf-test in a Nextflow project
1034-
2. How to write and run pipeline-level tests
1051+
2. How to write and run pipeline-level tests:
1052+
- Basic success testing
1053+
- Process count verification
1054+
- Output file existence checks
10351055
3. How to write and run process-level tests
1036-
4. How to use snapshots to verify process outputs
1037-
5. How to run all tests in a repository with a single command
1056+
4. Two approaches to output validation:
1057+
- Using snapshots for complete output verification
1058+
- Using direct content assertions for specific content checks
1059+
5. Best practices for test naming and organization
1060+
6. How to run all tests in a repository with a single command
10381061

10391062
Testing is a critical part of pipeline development that helps ensure:
10401063

10411064
- Your code works as expected
10421065
- Changes don't break existing functionality
10431066
- Other developers can contribute with confidence
10441067
- Problems can be identified and fixed quickly
1068+
- Output content matches expectations
10451069

10461070
### What's next?
10471071

@@ -1051,5 +1075,6 @@ Check out the [nf-test documentation](https://www.nf-test.com/) for more advance
10511075
- Write tests for edge cases and error conditions
10521076
- Set up continuous integration to run tests automatically
10531077
- Learn about other types of tests like workflow and module tests
1078+
- Explore more advanced content validation techniques
10541079

1055-
Remember: Tests are living documentation of how your code should behave. The more tests you write, the more confident you can be in your pipeline's reliability.
1080+
Remember: Tests are living documentation of how your code should behave. The more tests you write, and the more specific your assertions are, the more confident you can be in your pipeline's reliability.

side-quests/solutions/nf-test/tests/main.nf.test

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ nextflow_pipeline {
1414
then {
1515
assert workflow.success
1616
assert workflow.trace.tasks().size() == 6
17+
}
18+
19+
}
20+
21+
test("Should produce correct output files") {
22+
23+
when {
24+
params {
25+
input_file = "${projectDir}/greetings.csv"
26+
}
27+
}
28+
29+
then {
1730
assert file("$launchDir/results/Bonjour-output.txt").exists()
1831
assert file("$launchDir/results/Hello-output.txt").exists()
1932
assert file("$launchDir/results/Holà-output.txt").exists()
@@ -23,5 +36,4 @@ nextflow_pipeline {
2336
}
2437

2538
}
26-
2739
}

0 commit comments

Comments
 (0)