Unit testing is an indispensable aspect of software development. Testing gives us confidence that our code works fine and provides us a safety net when refactoring. Fortunately, Gradle's Java plugin makes it simple and easy to unit test your code.
We will write a simple test for the same example app we created above. We will create our first unit test now using JUnit (v4.12) library.
More information about JUnit can be found at http://junit.org.
Again, like Maven, Java test sources are kept in the
src/test/java directory relative to the project root. We will create this directory and, as a good practice, the test package structure will reflect the same hierarchy as the source packages.
... src └── test └── java // test source root └── com └── packtpub └── ge └── hello └── GreetingServiceTest.java ...
We will add test for the
GreetingService. By convention, the...