Java Software Testing tutorials: unit testing, open source, JUnit, Mockito, TestNG, Spring, JGiven, etc.
The testing strategy to adopt when you you run your code inside a Java EE container is the topic discussed in this blog post by Antonio Goncalves. To solve this issue, he presents a detailed step by step process to unit test an EJB with Mockito and how to do integration test with and without Arquillian with code samples. His conclusion is that since Java EE 6 it is now easy to use container and services in an embedded mode. Unit testing is good to test business code or code in isolation (mocking external components) but you have to remember that you should also use integration testing to test code interacting with external components or services.
In the context of Java unit testing, a sleeping snail is a test that’s sluggish and takes (relatively speaking) forever to run because it relies on Thread#sleep and arbitrarily long waits to allow threads to execute before performing assertions or continuing with the workflow under test. In this article, based on chapter 5 of Unit Testing in Java, author Lasse Koskela explains this code smell and the appropriate deodorant with an example
This presentation addresses the missing link in Enterprise Java development: simple, easy integration testing. You will learn how the simplified component model of Java EE can be applied to testable development.
Mockito is an open source mocking framework for Java. In this series of blog posts, Holger Staudacher shares his experiences with Mockito. He defines “effective” as arriving at clean test and production code as fast as possible. The first post of Effective Mockito explains how to setup Mockito in the Eclipse IDE for the daily work. The second post focuses on Mockito’s @Mock Annotation.
Thucydides is an open source tool that lets you use WebDriver-based unit or Behavior Driven Development (BDD) tests to write more flexible and more reusable WebDriver-based tests, and also to generate documentation about your acceptance tests. In this blog post, John Ferguson Smart explains how you can use Spring dependencies in your acceptance tests with Thucydides if you need to run your acceptance tests against an embedded web server.
Integration tests are performed after a successful execution of unit tests. Integration tests are, therefore, executed less frequently, because unit tests will naturally fail often. With this strict separation between unit tests and integration tests, we can save several minutes (sometimes, hours) with each turnaround. This article explains how integration testing can increase your productivity and ensure the deployability of your Java EE 6 application.
This is a brief video on how to use the JUnit open source unit testing framework for Java. By using JUnit, you can assert that methods in your Java code work as designed, without the need to set up the complete application.