A JUnit extension to learn through unit tests. Inspired by the famous Ruby Koans this project provides generic JUnit runners to write koans in Java.
Koans are just unit tests! A Koan Suite is a set of failing test classes that explain a certain technology or framework to the user. The task for the user is to get all tests green and "reach enlightment". To achieve this the koans-runner provides continuous feedback and reproducible test execution.
Download the koans-runner from Maven Central or add the dependency to your pom.
<dependency>
<groupId>com.tasktop.koans</groupId>
<artifactId>koans-runner</artifactId>
</dependency>
To create your own Koans you need to provide two things:
- One or more Test classes. They need to use
@RunWith( KoanRunner.class )
to be executed in the same order as the methods are defined in the source code.
@RunWith( KoanRunner.class )
public class MyTest {
@Test
public void easyFirstTest() {
fail(); // remove this line to make the test green
}
@Test
public void notSoEasySecondTest() {
assertTrue(false); // figure out how to pass the assertion
}
}
- One Suite class that defines the Test classes in the order to execute. This suite needs to use the
@RunWith( KoanSuiteRunner.class )
to produce the zen like output.
@RunWith( KoanSuiteRunner.class )
@SuiteClasses( {
MyTest.class
})
public class MySuite {}
To enable the ansi colors like in the screenshot above you need to add the -Denable.ansi=true
property when launching your test suite. To get these nice ansi colors within Eclipse you can install the nice ansi-econsole.
All code in this repository is published under terms of the Apache 2.0 Software License.