groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject incubator-groovy git commit: GROOVY-7474: Difference between junit3 and junit 4 shouldFail {...} not described in docs
Date Tue, 07 Jul 2015 10:05:17 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/master 63afb6d7e -> cb87dfc6d


GROOVY-7474: Difference between junit3 and junit 4 shouldFail {...} not described in docs


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/cb87dfc6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/cb87dfc6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/cb87dfc6

Branch: refs/heads/master
Commit: cb87dfc6de38f0d608fa7f522b600a69919482e5
Parents: 63afb6d
Author: Dmitry Andreychuk <and.dmitry@gmail.com>
Authored: Mon Jul 6 22:55:01 2015 +0300
Committer: paulk <paulk@asert.com.au>
Committed: Tue Jul 7 20:04:35 2015 +1000

----------------------------------------------------------------------
 src/spec/doc/core-testing-guide.adoc               | 10 ++++++++++
 .../test/testingguide/JUnit4ExampleTests.groovy    | 17 +++++++++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/cb87dfc6/src/spec/doc/core-testing-guide.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-testing-guide.adoc b/src/spec/doc/core-testing-guide.adoc
index 1e893d9..3d993b9 100644
--- a/src/spec/doc/core-testing-guide.adoc
+++ b/src/spec/doc/core-testing-guide.adoc
@@ -471,6 +471,16 @@ As can be seen in the example above, the static methods found in `GroovyAssert`
 with the introduction of the power assertion statement, it turned out to be _good practice
to rely on assertion statements_
 instead of using the JUnit assertion methods with the improved message being the main reason.
 
+It is worth mentioning that `GroovyAssert.shouldFail` is not absolutely identical to `GroovyTestCase.shouldFail`.
While
+`GroovyTestCase.shouldFail` returns the exception message, `GroovyAssert.shouldFail` returns
the exception itself. It
+takes a few more keystrokes to get the message, but in return you can access other properties
and methods of the
+exception:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/testingguide/JUnit4ExampleTests.groovy[tags=should_fail_return,indent=0]
+----
+
 == Testing with Spock
 
 Spock is a testing and specification framework for Java and Groovy applications. What makes
it stand out from the

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/cb87dfc6/src/spec/test/testingguide/JUnit4ExampleTests.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/testingguide/JUnit4ExampleTests.groovy b/src/spec/test/testingguide/JUnit4ExampleTests.groovy
index 969ab08..dfb4cf7 100644
--- a/src/spec/test/testingguide/JUnit4ExampleTests.groovy
+++ b/src/spec/test/testingguide/JUnit4ExampleTests.groovy
@@ -31,5 +31,22 @@ class JUnit4ExampleTests {
             numbers.get(4)
         }
     }
+
+    // end::junit4_example[]
+
+    // tag::should_fail_return[]
+    @Test
+    void shouldFailReturn() {
+        def e = shouldFail {
+            throw new RuntimeException('foo',
+                                       new RuntimeException('bar'))
+        }
+        assert e instanceof RuntimeException
+        assert e.message == 'foo'
+        assert e.cause.message == 'bar'
+    }
+    // end::should_fail_return[]
+
+    // tag::junit4_example[]
 }
 // end::junit4_example[]


Mime
View raw message