Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luontola/nestedjunit
Nested contexts for JUnit to organize tests better
https://github.com/luontola/nestedjunit
Last synced: 4 days ago
JSON representation
Nested contexts for JUnit to organize tests better
- Host: GitHub
- URL: https://github.com/luontola/nestedjunit
- Owner: luontola
- License: apache-2.0
- Created: 2012-11-01T08:48:09.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-11-05T19:59:17.000Z (about 12 years ago)
- Last Synced: 2024-04-15T07:10:12.788Z (7 months ago)
- Language: Java
- Homepage:
- Size: 199 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
NestedJUnit
===========Enables you to organize JUnit tests in a hierarchy, so that the nested
test classes can reuse the context from the outermost test class. This
makes it easier to write [expressive tests][naming-tests].NestedJUnit can be downloaded from [Maven Central][download] and is
licensed under Apache License 2.0. NestedJUnit used to be embedded in
[TDD Tetris Tutorial][tdd-tutorial], but due to popular demand is now
available as a standalone library.As a usage example, have a look at [StackTest]:
```java
@RunWith(NestedJUnit.class)
public class StackTest {private Deque stack;
@Before
public void createStack() {
stack = new ArrayDeque();
}public class An_empty_stack {
@Test
public void is_empty() {
assertTrue(stack.isEmpty());
}@Test
public void After_a_push_the_stack_is_no_longer_empty() {
stack.push("a push");
assertFalse(stack.isEmpty());
}
}public class When_objects_have_been_pushed_onto_a_stack {
@Before
public void pushObjects() {
stack.push("pushed first");
stack.push("pushed last");
}@Test
public void the_object_pushed_last_is_popped_first() {
String poppedFirst = stack.pop();
assertThat(poppedFirst, is("pushed last"));
}@Test
public void the_object_pushed_first_is_popped_last() {
stack.pop();
String poppedLast = stack.pop();
assertThat(poppedLast, is("pushed first"));
}@Test
public void After_popping_all_objects_the_stack_is_empty() {
stack.pop();
stack.pop();
assertTrue(stack.isEmpty());
}
}
}
```[naming-tests]: http://blog.orfjackal.net/2010/02/three-styles-of-naming-tests.html
[download]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22net.orfjackal.nestedjunit%22
[tdd-tutorial]: https://github.com/orfjackal/tdd-tetris-tutorial
[StackTest]: https://github.com/orfjackal/nestedjunit/blob/master/src/test/java/net/orfjackal/nestedjunit/StackTest.javaVersion History
---------------**1.0.0 (2012-11-05)**
- Runs `@Test` annotated test methods from two levels: the topmost test class (same as JUnit) and its non-static member classes
- Runs `@Before`, `@After` and `@Rule` from all levels
- Runs `@BeforeClass`, `@AfterClass` and `@ClassRule` from the topmost level
- The nested test classes have access to member variables from the topmost test class, and any side effects are isolated the same way as in JUnitKnown issues:
- Fails if a test class contains public member classes which do not have test methods
- Does not fail if there are no tests in a test class nor its nested test classes