Aşağıdaki gibi iki java sınıfı bulunmaktadır:
public class Toplar {
public int topla(int a, int b){
return a+b;
}
}
public class Carpar {
public int carp(int a, int b){
return a*b;
}
}
Yukarıdaki iki sınıf için ayrı aşağıdaki gibi iki test sınıfı yapılmıştır:
import static org.junit.Assert.*;
import org.junit.*;
public class ToplaTest {
Toplar simple;
@Before
public void setUp(){
simple=new Toplar();
}
@Test
public void testTopla(){
int c=simple.topla(1,2);
assertEquals(3, c);
}
}
import static org.junit.Assert.*;
import org.junit.*;
public class CarpTest {
Carpar simple;
@Before
public void setUp(){
simple=new Carpar();
}
@Test
public void testCarp(){
int c=simple.carp(1,2);
assertEquals(2, c);
}
}
Yukarıdaki iki testi aynı anda çalıştırabilmek için aşağıdaki gibi bir suite yaratılabilir:
import org.junit.runner.*;
import org.junit.runners.*;
@RunWith(Suite.class)
@Suite.SuiteClasses({
ToplaTest.class,
CarpTest.class
})
public class IslemSuit {
}
Yukarıdaki suit, ToplaTest ve CarpTest sınıflarını içermektedir. IslemSuit çalıştırılırsa önce ToplaTest , ardından da CarpTest sınıfları çalışacaktır