Statistical Unit Tests with ensure4j
As part of another project I am developing ensure4j. The syntax (see the examples here) is working quite nicely, ensure4j is already very useful for internal use.
Lately I was busy adding tests that are able to verify if some code (e.g. an optimizer that uses random, like genetic algorithm, simulated annealing, …) produces the desired in e.g. 95% of the cases (Wikipedia has a nice practical example for confidence intervals).
Example Usage
Here is an example that tests the nonsense code Math.random() * 2.
ensure(new Experiment() {
public double measure() {
return Math.random() * 2;
}
}).between(0.9, 1.1, 0.95).sample(10, 100);
The code most likely does not make much sense out of context like this, so here is an explanation of what it does:
Redesigning JUnit Asserts
After reading about Behaviour Driven Development, using jMock for a while, and since I am very fond of Ruby‘s core class APIs, I am sure the assertations of JUnit need a major overhaul.
This are the goals I have for the redesign: