UDTopia aims to be a foundational element of your app. To earn that trust, UDTopia must have exceptional quality and reliability. High-quality testing leads to high-quality software.
Below are the details of these goals, and guidelines on how to achieve them.
Use JUnit 4 for unit tests. Use Mockito for stubbing/mocking.
Use JaCoCo to measure code coverage. Branch coverage should be 100%.
Use assertions to check method usage and parameters. Assertions should be enabled in Dev and Test environments, and disabled in Staging and Production.
JaCoCo has trouble with assert
statements.
It always reports missed branches, whether assertions are enabled or not.
Instead of invoking assert
directly, use UDTopia’s Assert
class, like this:
Using assert |
Using Assert |
---|---|
assert str.startsWith(“A”) |
Assert.that(() -> str.startsWith(“A”)) |
assert !str.isEmpty() |
Assert.not(str::isEmpty) |
assert str != null |
Assert.notNull(() -> str) |
assert str != null : “str is null!” |
Assert.notNull(() -> str, “str is null!”) |
More details in the docs.
Use PIT mutation testing to measure test strength.
UDTopia test strength should be 100%, with the STRONGER
mutator group.
Use JMH to measure performance.
To make benchmarking easier, BaseBenchmark
takes care of the boilerplate code.
public class StringBenchmark extends BaseBenchmark
{
public static void main(String[] args) { runBenchmark(args); }
@Benchmark public boolean stringEmpty() { return RAND_STR.get().isEmpty(); }
@Benchmark public boolean stringPrefix() { return RAND_STR.get().startsWith(“A”); }
@Benchmark public boolean numberEven() { return RAND.nextInt() % 2 == 0; }
}
BaseBenchmark
provides convenient APIs for generating random content in benchmark tests.
More details in the docs.