nushell/crates/nu-std/tests
Máté FARKAS c3678764b4
stdlib test runner: implement setup and teardown commands to unit tests (#8776)
# Description

As in other testing frameworks, the `setup` runs before every test case,
and the `teardown` after that. A context can be created in `setup`,
which will be in the `$in` variable in the test cases, and in the
`teardown`. The `teardown` is called regardless of the test is passed,
skipped, or failed.

For example:

```nushell
use std.nu *

export def setup [] {
    log debug "Setup is running"
    {msg: "This is the context"}
}

export def teardown [] {
    log debug $"Teardown is running. Context: ($in)"
}

export def test_assert_pass [] {
    log debug $"Assert is running. Context: ($in)"
}

export def test_assert_skip [] {
    log debug $"Assert is running. Context: ($in)"
    assert skip
}

export def test_assert_fail_skipped_by_default [] {
    log debug $"Assert is running. Context: ($in)"
    assert false
}
```


![image](https://user-images.githubusercontent.com/282320/230466359-9908cc72-edbd-4150-9aff-d15fe42c0cc7.png)

# After Submitting

I'll update the documentation.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-04-10 22:42:11 +02:00
..
run.nu stdlib test runner: implement setup and teardown commands to unit tests (#8776) 2023-04-10 22:42:11 +02:00
test_asserts.nu stdlib: refactor into a multi-module library (#8815) 2023-04-09 20:00:20 +03:00
test_dirs.nu stdlib test runner: implement setup and teardown commands to unit tests (#8776) 2023-04-10 22:42:11 +02:00
test_logger.nu stdlib: refactor into a multi-module library (#8815) 2023-04-09 20:00:20 +03:00
test_setup_teardown.nu stdlib test runner: implement setup and teardown commands to unit tests (#8776) 2023-04-10 22:42:11 +02:00
test_std.nu stdlib: refactor into a multi-module library (#8815) 2023-04-09 20:00:20 +03:00
test_xml.nu stdlib test runner: implement setup and teardown commands to unit tests (#8776) 2023-04-10 22:42:11 +02:00