nitunit: update documentation for annotations
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 6 Jun 2017 05:18:45 +0000 (01:18 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 6 Sep 2017 22:58:06 +0000 (18:58 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

share/man/nitunit.md
src/testing/README.md

index 0ab13a5..2263bd3 100644 (file)
@@ -131,25 +131,24 @@ This flag can be used by libraries and program to prevent (or limit) the executi
 
 TestSuites are Nit modules that define a set of TestCases.
 
-A test suite is a module that uses the annotation `is test_suite`.
+A test suite is a module that uses the annotation `is test`.
 
 It is common that a test suite focuses on testing a single module.
-In this case, the name of the test_suite is often `test_foo.nit` where `foo.nit` is the tested module.
+In this case, the name of the test suite is often `test_foo.nit` where `foo.nit` is the tested module.
 
 The structure of a test suite is the following:
 
 ~~~~
 # test suite for module `foo`
-module test_foo is test_suite
+module test_foo is test
 
-import test_suite
 import foo # can be intrude to test private things
 
 class TestFoo
-       super TestSuite
+    test
 
     # test case for `foo::Foo::baz`
-    fun test_baz do
+    fun baz is test do
         var subject = new Foo
         assert subject.baz(1, 2) == 3
     end
@@ -160,18 +159,18 @@ Test suite can be executed using the same `nitunit` command:
 
     $ nitunit foo.nit
 
-`nitunit` will execute a test for each method named `test_*` in a class
-subclassing `TestSuite` so multiple tests can be executed for a single method:
+`nitunit` will execute a test for each method with the `test` annotation in a class
+also annotated with `test` so multiple tests can be executed for a single method:
 
 ~~~~
 class TestFoo
-       super TestSuite
+    test
 
-    fun test_baz_1 do
+    fun baz_1 is test do
         var subject = new Foo
         assert subject.baz(1, 2) == 3
     end
-    fun test_baz_2 do
+    fun baz_2 is test do
         var subject = new Foo
         assert subject.baz(1, -2) == -1
     end
@@ -204,12 +203,12 @@ The `diff(1)` command is used to perform the comparison.
 The test is failed if non-zero is returned by `diff`.
 
 ~~~
-module test_mod is test_suite
+module test_mod is test
 
 class TestFoo
-       super TestSuite
+       test
 
-       fun test_bar do
+       fun bar is test do
                print "Hello!"
        end
 end
@@ -228,25 +227,27 @@ To helps the management of the expected results, the option `--autosav` can be u
 
 ## Configuring TestSuites
 
-`TestSuite`s also provide methods to configure the test run:
-
-`before_test` and `after_test`: methods called before/after each test case.
+`TestSuite`s also provide annotations to configure the test run:
+`before` and `after` annotations can be applied to methods that must be called before/after each test case.
 They can be used to factorize repetitive tasks:
 
 ~~~~
 class TestFoo
-       super TestSuite
+    test
+
     var subject: Foo
+
     # Mandatory empty init
     init do end
+
     # Method executed before each test
-    fun before_test do
+    fun set_up is before do
         subject = new Foo
     end
-    fun test_baz_1 do
+    fun baz_1 is test do
         assert subject.baz(1, 2) == 3
     end
-    fun test_baz_2 do
+    fun baz_2 is test do
         assert subject.baz(1, -2) == -1
     end
 end
@@ -254,7 +255,7 @@ end
 
 When using custom test attributes, an empty `init` must be declared to allow automatic test running.
 
-`before_module` and `after_module`: methods called before/after each test suite.
+`before_all` and `after_all` annotations can be applied to methods that must be called before/after each test suite.
 They have to be declared at top level:
 
 ~~~~
@@ -279,11 +280,11 @@ end
 The `NIT_TESTING_PATH` environment variable contains the current test suite
 file path.
 Nitunit define this variable before the execution of each test suite.
-It can be used to access files based on the current test_suite location:
+It can be used to access files based on the current test suite location:
 
 ~~~
 class TestWithPath
-       super TestSuite
+    test
 
     fun test_suite_path do
         assert "NIT_TESTING_PATH".environ != ""
index 772ec38..a0addf1 100644 (file)
@@ -49,20 +49,19 @@ To test a method you have to instanciate its class:
 
 TestSuites are Nit files that define a set of TestCase for a particular module.
 
-The test suite module must be declared using the `test_suite` annotation.
+The test suite module must be declared using the `test` annotation.
 The structure of a test suite is the following:
 
        # test suite for module `foo`
-       module test_foo is test_suite
+       module test_foo is test
 
-       import test_suite # import the `TestSuite` class and the `test_suite` annotation
        import foo # can be intrude to test private things
 
        class TestFoo
-               super TestSuite
+               test
 
                # test case for `foo::Foo::baz`
-               fun test_baz do
+               fun baz is test do
                        var subject = new Foo
                        assert subject.baz(1, 2) == 3
                end
@@ -79,18 +78,18 @@ Otherwise, you can use the `-t` option to specify the test suite module name:
 
        $ nitunit foo.nit -t my_test_suite.nit
 
-`nitunit` will execute a test for each method named `test_*` in a class named `Test*`
+`nitunit` will execute a test for each method annotated with `test` in a class also annotated with `test`
 so multiple tests can be executed for a single method:
 
        class TestFoo
-               super TestSuite
+               test
 
-               fun test_baz_1 do
+               fun baz_1 is test do
                        var subject = new Foo
                        assert subject.baz(1, 2) == 3
                end
 
-               fun test_baz_2 do
+               fun baz_2 is test do
                        var subject = new Foo
                        assert subject.baz(1, -2) == -1
                end
@@ -98,51 +97,50 @@ so multiple tests can be executed for a single method:
 
 `TestSuites` also provide methods to configure the test run:
 
-`before_test` and `after_test`: methods called before/after each test case.
+`before` and `after` annotations can be added to methods that must be called before/after each test case.
 They can be used to factorize repetitive tasks:
 
        class TestFoo
-               super TestSuite
+               test
 
                var subject: Foo is noinit
 
                # Method executed before each test
-               redef fun before_test do
+               redef fun set_up is before do
                        subject = new Foo
                end
 
-               fun test_baz_1 do
+               fun baz_1 is test do
                        assert subject.baz(1, 2) == 3
                end
 
-               fun test_baz_2 do
+               fun baz_2 is test do
                        assert subject.baz(1, -2) == -1
                end
        end
 
 When using custom test attributes, a empty init must be declared to allow automatic test running.
 
-`before_module` and `after_module`: methods called before/after each test suite.
+`before_all` and `after_all` annotations can be set on methods that must be called before/after each test suite.
 They have to be declared at top level:
 
        module test_bdd_connector
 
-       import test_suite
        import bdd_connector
 
        # Testing the bdd_connector
        class TestConnector
-               super TestSuite
+               test
                # test cases using a server
        end
 
        # Method executed before testing the module
-       redef fun before_module do
+       fun before_module is before_all do
                # start server before all test cases
        end
 
        # Method executed after testing the module
-       redef fun after_module do
+       fun after_module is after_all do
                # stop server after all test cases
        end