Home » Core Java » junit (page 4)

junit

Junit Unrooted Tests

1. Introduction One common mistake that developers make in creating JUnit is the version mismatch. Projects seems to be now keen on creating Junit test cases using the more advance annotation based (JUnit 4) rather than the older way (Extending TestCase class) of doing it. A common error or issue is when a developer loads/imports a JUnit 4 on the ...

Read More »

JUnit Code Coverage

1. Introduction For all test cases, it is important that coverage always analyses the whole code. This is a definitive and statistical proof that all testable code is indeed tested. In this example, I’ll be showcasing how a developer can turn on and off their code coverage on their unit test cases. 2. Tools For this example, we’ll be using ...

Read More »

JUnit Disable Test Example

1. Introduction There are instances that our test cases aren’t ready yet and it would almost be certain that when we run our builds with these, there is a high probability that our test executions will fail. This can be avoided using the @Ignore annotation. Developers sometimes just pass the test case to avoid build failures (assert(true)). This is a ...

Read More »

JUnit Tutorial for Beginners

1. Introduction In this post, we will discus the basics of setting up your JUnit Test cases. We’ll go step by step in creating test cases as we go along with creating our application. Before we dive into it though, why do we even need to create test cases? Isn’t it enough to just create the implementation since it’s what ...

Read More »

JUnit Categories Example

1. Introduction JUnit has an awesome feature of organizing group of test cases called Categorizing. It can help developers differentiate test cases from one another. In this post, I’ll showcase how easy it is to categorize unit tests by @Category.             2. Maven Project and Configuration pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.jgc.areyes.junit</groupId> <artifactId>junit-categories-example</artifactId> ...

Read More »

JUnit Test Order Example

1. Introduction One of the rarely used features in JUnit is the usage of @FixMethodOrder annotation. This is primarily used to indicate an order of test method calls in a specific JUnit Test case class. This is actually not a recommended practice cause we want method calls to be independent and arbitrary in nature. Test cases method should not be ...

Read More »

“No JUnit Tests Found” Error Solution

1. Introduction One of the first steps that developers take in order to create Unit Test case is to ensure that their environment is ready. This means that all required libraries are setup properly and that the JUnit Test cases are correctly annotated. There might be a couple of technical hiccups like proper source folder configuration in your specific IDE, ...

Read More »

JUnit Integration Test Example

1. Introduction Integration tests are test cases that test highly coupled external services. A great example of this is services in a SOA environment. In this scheme we will create services (or micro services) that are usually deployed on a different container and only exposed specific implementation of it’s own, consumed by a more sophisticated system. By rule of thumb, we ...

Read More »

JUnit Best Practices

1. Introduction There are a lot of ways on how a developer can do JUnit test cases, but overall it really depends on the strategy of how a specific functional code can be tested to it’s limits. It’s the developers responsibility to introduce thorough test cases to make sure that the code is stable and ultimately does what it has ...

Read More »

JUnit NetBeans Example

1. Introduction In this post I will introduce the basics of writing and running JUnit unit tests in NetBeans IDE. Testing an application is an integral part of the development cycle, and writing and maintaining unit tests can help ensure that the individual methods in your source code work correctly. The IDE’s support for JUnit testing framework allows developers to ...

Read More »