sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 517 forks source link

Skip all tests if a particular test failed #129

Closed dchapkine closed 9 years ago

dchapkine commented 9 years ago

How do i handle dependencies between tests ?

Here is the situation: I need to have 3 docker containers with names a, b and c running before i can run any other test, because following tests all run inside this 3 containers

Here is what i have so far:

So, for now if test 1 fails, 2, 3, 4 are still executed and obviously they all fail too...

What would be cool is to be able to set a flag on test 1 telling that it's a critical test, and that the test suite should stop if test 1 fails. Something like this:

@test "my awesome test" critical {
  ...
}

or

@test "my awesome test" {
  critical
  ...
}

Does something like this exists in bats, and if not what is the closest alternative ?

For example is it possible to know if a particular test failed with some kind of function like: did_test_failed("my awesome test") ?

jvortmann commented 9 years ago

I think what you are looking for is a setup and teardown function https://github.com/sstephenson/bats#setup-and-teardown-pre--and-post-test-hooks

You can also create you own functions that check if containers are up before running the tests and start them if they are down. It is just a mather of calling this function on each test.

It is wrong to create dependent tests.

dchapkine commented 9 years ago

@jvortmann thank you for your suggestions.

I will try to rewrite my tests using setup & teardown instead of using first test as initialisation step.

I agree with the fact that ideally all tests should be independent... however in some cases it's better to have a way to stop your test suite if you know that everything else will fail. For example if your tests are heavy & slow, it will save you a lot of time.

A lot of test frameworks actually have a way to declare a dependency

Ex:

So, i don't think that adding some kind of lightweight dependency check to bats is a completely crazy idea.