Junit 4 allows you to run test classes in bulk by using test suite classes. To create a test suite for a set of test classes, add the following annotations for the test class:
@RunWith (Suite.class) @SuiteClasses (Testclass1.class, Testclass2.class)
When run, all test classes contained within the @suiteclasses annotation are executed. Junit 4 test suite Sample
In this case, Arithmetictest.java and Geometrictest.java will be executed with the JUnit test suite class Alltest.java
Arithmetic.java
Package in.co.javatutorials;
/**
* @author javatutorials.co.in * * Public
class arithmetic {public
int Add (int i, int j) {return
I + j;
}
}
Geometric.java
Package in.co.javatutorials;
/**
* @author javatutorials.co.in
*
/public class Geometry {public
int squarearea (int length) { C16/>return length * length;
}
}
Arithmetictest.java
Package in.co.javatutorials;
Import static org.junit.assert.*;
Import Org.junit.Test;
/**
* @author javatutorials.co.in
*
/public class Arithmetictest {
@Test public
void Testadd () {
arithmetic arithmetic = new arithmetic ();
int actualresult = Arithmetic.add (1, 2);
int expectedresult = 3;
Assertequals (Expectedresult, Actualresult);
}
Geometrictest.java
Package in.co.javatutorials;
Import static org.junit.assert.*;
Import Org.junit.Test;
/**
* @author javatutorials.co.in */public
class Geometrytest {
@Test public
void Testsquarearea () {
Geometry Geometry = new Geometry ();
int actualresult = Geometry.squarearea (2);
int expectedresult = 4;
Assertequals (Expectedresult, Actualresult);
}
Alltests.javaTest Suite Class
Package in.co.javatutorials;
Import Org.junit.runner.RunWith;
Import Org.junit.runners.Suite;
Import org.junit.runners.Suite.SuiteClasses;
/**
* @author javatutorials.co.in * *
@RunWith (suite.class)
@SuiteClasses ({ Arithmetictest.class, Geometrytest.class}) public
class Alltests {
}
result Output
Source Download
Click My download source
Tutorial Directory Navigation
Introduction to the JUnit test framework Junit Eclipse Tutorial Junit 4 Annotations Junit 4 Assertion Method (Assert methods) Junit 4 Parameterized testing Junit 4 Testing Suite ( test suite) Junit 4 Ignore test (Ignoretest) Junit 4 Timeout test (Timeout test)
--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------this source for Http://blog.csdn.net/luanlouis, reproduced please indicate the source, thank you.