In this post I’d like to briefly present extended approach to provide fixtures into JUnit tests. JUnit already provides a possibility to execute methods right before/after test method and before/after test class. This standard functionality does not fulfill more sophisticated requirements. Thanks to @Beofre/@After annotations, for each test there is always executed exactly the same method. In a case in which we’d like to have a dedicated fixture code for each method the existing approach is not so convenient. I’ve developed fixture handling addition to JUnit framework with a possibility to define different fixture for each test.
Tag Archives: Unit test
Employing Java 8 in service layer
The purpose of this post is to take a look on lambda expressions introduced in Java SE 8 and using them in service layer making code more concise and sophisticated as well. The focus is put on services implementation. The CarService is introduced here as an example. Emphasis is put on Java8 lambda expressions, java.util.function package, especially on Predicate and Function. New features is a must in Java world. The possibilities do not bring new values in programming languages in general. They are already known from other languages. However, Java is a really general purpose programming language and it always takes time to introduce new features and ensuring production-ready platform. This post is code oriented. The most significant code snippets are provided throughout the content whereas the complete sources can be found on softexploration github.
Testing (in)finite loops with Java 8 enabled unit tests
This post is an extension to the Infinite loops, halting problem and FindBugs containing slightly refactored core code and prepared unit tests using Java SE 8 capabilities. The main extension point is the class LoopUtils which provides methods allowing to verify loops finiteness. Thanks to these methods it is possible to classify methods to finite and infinite. Finiteness is determined by a flexible defined timeout. When a single method’s execution time reaches value of timeout then an execution is classified as infinite. The new code takes advantages on few Java SE 8 new possibilities. The source code is in the same repository but in a dedicated java8enabled branch .