Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You can also use Boost's testing facilities. An example (Foo and Person classes not shown) to give you a flavor of these kinds of tests:

Code Block
@PackageScope
class StringJoinerTest extends GroovyLifecycleTestCase implements HasFixtures, InjectableSubject, InjectableTest, LazyFields  {
    StringJoiner subject
    private Person pa, pb
    Foo fooA, fooB
    Foo foo1Mock, foo2Mock

    void fixtures() {
        pa = new Person(first:'f1', last:'l1')
        pb = new Person(first:'f2', last:'l2')
    }

    void testLookup() {
        expect.oneCall(foo1Mock, "FOO", "toUpperCase")
        expect.oneCall(foo2Mock, "BAR", "toUpperCase")
        assert subject.join(pa.first, pb.last) == "f1l2"
        assert subject.join(fooA.bar, fooB.bar) == "barbar"
        assert subject.joinUpper(foo1Mock, foo2Mock) == "FOOBAR"
    }
}

Here, fooA, fooB and subject will be auto created with default values, foo1Mock and foo2Mock will be auto created as mocks, pa and pb are set using the fixtures() method. GroovyLifecycleTestCase is a slight variation of LifecycleTestCase which is built-in to Boost. The built-in one is a little too opinionated about the methods Groovy adds under the covers to its classes. The result is very compact test code albeit looking a little magical until you get used to this style of testing.