O'Reilly logo

Sonar Code Quality Testing Essentials by Charalampos Arapidis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

jUnit Quickstart

jUnit is a framework for writing and running test cases—http://junit.org/. A test is a Java class containing jUnit annotations to set up the test and identify test methods. Basically, you annotate test methods with the @Test annotation and verify results using assertion. When you want to check a value dependent on the nature of the check and the type of the value, you call the appropriate assertion.

For example, if you want to check that the value of a Boolean variable is true, you would write: assertTrue(var). There are many different assertions located in package import org.junit.Assert.*. Notice that you have to import this package statically to each test class. Methods containing test code are annotated with @org.junit.Test ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required