-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Sonar Code Quality Testing Essentials
By :

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
. For example:
@Test public void testFoo(){ .. }
To start writing your own tests, download junit-4.xx.jar
from https://github.com/KentBeck/junit/downloads and add it to the class path.
Next, we will go through a basic test...
Change the font size
Change margin width
Change background colour