Best practice questions: nf-test assertion pattern...
# nf-test
m
Best practice questions: nf-test assertion patterns 1. Content checks inside snapshot() vs. independent assert? The assertions guide shows content checks (.contains(), readLines(), etc.) as independent asserts, separate from snapshot() — citing bismark/align as the example (it's in the title of the block but not rendered). But the current bismark/align/tests/main.nf.test doesn't do that anymore — it folds the same kind of check (readLines().contains(...)) as an argument inside snapshot(...).match(), alongside bam(...).getReadsMD5(). The doc's own cited example moved past what the doc shows (doc last edited May 19, file last updated Jul 29). 2. assertAll() vs. bare sequential assert statements? The docs say to "group all assertions within assertAll()," but plenty of modules (including some recently touched) still use bare sequential assert statements directly in then {} with no assertAll() wrapper at all. Is bare-assert still acceptable, or should everything be migrated to assertAll()? Came up reviewing a PR with several conditional file-content checks and wanted to point the contributor at the right convention rather than guess.
j
1. I don't think there's any benefit to wrapping plain boolean assertions inside the snapshot. The snapshot should be retained only for capturing actual content, either as an md5sum or a direct extract. If you capture a bare boolean assertion in the snapshot it just prints a bare "true" in there which is not very useful when debugging. 2. AFAIK wrapping assertions in assertAll() means that all assertions are checked and then a single true/false is passed. Depending on what those assertions are, that could take some time - that's why the
assert process.success
assertion is outside of the function, to fail the test as soon as possible. But in general I'm not sure if any particular way is better or worse?
m
Thanks. Then I'll reply it's fine that the plain booleans are outside the snapshot (confirmed my thinking too), and that the bare asserts should be wrapped in an
assertAll