Merge: nitunit: some fixes and improvements for the `before_all`, `after_all` annotations
This PR does three things:
* fixes the importation of `before_all` and `after_all` methods
* allows use of `before_all` and `after_all` methods within classes
* changes the test execution order for imported test suites
### Fix the importation of `before_all` and `after_all` methods
First of all, this PR fixes the behavior of nitunit with multiple test_suite importation.
Be two modules `a` and `b`:
~~~nit
module a is test
class TestA
test
# some test cases
end
fun setup is before_all do # important things
~~~
~~~nit
module b is test
import module a
class TestB
super TestA
test
end
~~~
In this case, because `b` does not introduce any `before_all` method, the method from `a` was not executed.
This is fixed now.
### Class-level `before_all` and `after_all` methods
`before_all` and `after_all` can now be used inside a class definition to indicate methods that must be executed before / after all methods inside the class:
~~~nit
class TestC
test
fun setup is before_all do # something before all test cases of `TestC`
# some test cases
end
~~~
### Tests execution order
Methods with `before*` and `after*` annotations are linearized and called in different ways.
* `before*` methods are called from the least specific to the most specific
* `after*` methods are called from the most specific to the least specific
~~~nit
module test_bdd_connector
import bdd_connector
# Testing the bdd_connector
class TestConnector
test
# test cases using a server
end
# Method executed before testing the module
fun setup_db is before_all do
# start server before all test cases
end
# Method executed after testing the module
fun teardown_db is after_all do
# stop server after all test cases
end
~~~
When dealing with multiple test suites, niunit allows you to import other test suites to factorize your tests:
~~~nit
module test_bdd_users
import test_bdd_connector
# Testing the user table
class TestUsersTable
test
# test cases using the db server from `test_bdd_connector`
end
fun setup_table is before_all do
# create user table
end
fun teardown_table is after_all do
# drop user table
end
~~~
In the previous example, the execution order would be:
1. `test_bdd_connector::setup_db`
2. `test_bdd_users::setup_table`
3. `all test cases from test_bdd_users`
4. `test_bdd_users::teardown_table`
5. `test_bdd_connector::teardown_db`
Pull-Request: #2572