Wiki source code of WOUnit
Version 2.1 by Henrique Prange on 2011/06/17 19:52
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | == Introduction == | ||
2 | |||
3 | The WOUnit framework contains a set of utilities for testing WebObjects applications using JUnit 4.7 or later capabilities. This library can be useful if you write unit/integration tests for Enterprise Objects or employ the TDD technique on your projects. | ||
4 | |||
5 | WOUnit is free software released under the Apache 2 license. Visit the WOUnit [[website>>http://hprange.github.com/wounit]] for more information and a complete guide on how to use this framework. | ||
6 | |||
7 | == Usage == | ||
8 | |||
9 | Here is a brief example that demonstrates some of the features of WOUnit: rules, special annotations and specific matchers for assertion. | ||
10 | |||
11 | {{code title="FooTest.java"}} | ||
12 | |||
13 | import static com.wounit.matchers.EOAssert.*; | ||
14 | import com.wounit.rules.MockEditingContext; | ||
15 | import com.wounit.annotations.Dummy; | ||
16 | import com.wounit.annotations.UnderTest; | ||
17 | |||
18 | public class FooTest { | ||
19 | @Rule | ||
20 | public MockEditingContext ec = new MockEditingContext("MyModel"); | ||
21 | |||
22 | @Dummy | ||
23 | private Bar dummyBar; | ||
24 | |||
25 | @UnderTest | ||
26 | private Foo foo; | ||
27 | |||
28 | @Test | ||
29 | public void cantSaveFooWithOnlyOneBar() { | ||
30 | foo.addToBarRelationship(dummyBar); | ||
31 | |||
32 | confirm(foo, cannotBeSavedBecause("Foo must have at least 2 bars related to it")); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | {{/code}} |