GrooBe allows you to use should-be assertions on Groovy unit tests. At the moment we support the following:
-
Equality assertions
shouldBeandshouldNotBeshouldEqualandshouldNotEqualshouldBeEqualandshouldNotBeEqualshouldBeEqualToandshouldNotBeEqualTo
-
Instance assertions
- "instance of" tests with
shouldBeAandshouldBeAn, with the respectiveshouldNotBeAandshouldNotBeAn
- "instance of" tests with
-
Comparable assertions
shouldBeGreaterThanshouldBeLessThan
-
String assertions
shouldStartWithandshouldNotStartWithshouldEndWithandshouldNotEndWithshouldContainandshouldNotContainshouldBeEmptyandshouldNotBeEmpty
-
Map assertions
shouldHaveKeyandshouldNotHaveKeyshouldHaveValueandshouldNotHaveValueshouldHaveEntryandshouldNotHaveEntryshouldBeEmptyandshouldNotBeEmpty
-
Collection assertions
shouldContainandshouldNotContainshouldBeEmptyandshouldNotBeEmpty
-
Closure assertions
shouldFailWith
Just add GrooBe as a dependency on your Maven pom.xml file:
<dependency>
<groupId>com.github.tanob</groupId>
<artifactId>groobe</artifactId>
<version>1.1</version>
</dependency>
Being based on the hamcrest test expressions allows GrooBe to be used with JUnit or TestNG.
Here is an example of how you use it with JUnit4, there are several other examples in the src/test directory:
import com.github.tanob.groobe.GrooBe
import org.junit.Before
import org.junit.Test
public class ExampleTest {
@Before
public void before() {
GrooBe.activate()
}
@Test
public void someShouldBeAssertions() {
(2*2).shouldNotBe 5
1.shouldBeAn Integer
"a different string".shouldNotContain "the same string"
}
}
I would like to thank Paul Hammant (http://paulhammant.com/) for all his help and for suggesting the name GrooBe for the project.
We use a BSD license as you can see in our LICENSE.txt.