Overview
Junitcore as the JUNIT4 entry class (containing the static Main method), defines a series of methods to start junit completion of reflection execution on the test class
Using the following programming methods:
public static void Main (string[] args) {
results result = junitcore.runclasses (mytest.class);//Test class object for
( Failure Failure:result.getFailures ()) {//Fail print failure information
System.out.println (failure.tostring ()) for failure to execute
;}
START Process
1, create a default computer (responsible for calling Runnerbuilder Create runner instance), call the following code
public static result Runclasses (Computer Computer, Class<?> ... classes) {return
new Junitcore (). Run (Computer , classes);
}
2, according to the incoming class object, constructs a request, the code is as follows
Public result Run (Computer Computer, Class<?> ... classes) {return
run (request.classes (Computer, classes)) c2/>}
Create different Runnerbuilder according to different annotations, such as @test words is Junit4builder
The annotations on classes and methods are scanned and validated when the runner is created to construct the correct test logic
public static Request classes (Computer Computer, Class<?> ... classes) {
try {
Alldefaultpossibilitiesbuilder builder = new Alldefaultpossibilitiesbuilder ();
Runner suite = Computer.getsuite (builder, classes);
Return runner (suite);
catch (Initializationerror e) {return
runner (new Errorreportingrunner (E, classes));
}
3, according to reqeust get runner and start
Public result run (Request request) {return
run (Request.getrunner ());
}
Public result Run (Runner Runner) {result result
= new result ();
Runlistener listener = Result.createlistener ();
Notifier.addfirstlistener (listener);
try {
notifier.firetestrunstarted (runner.getdescription ());
Runner.run (notifier);
Notifier.firetestrunfinished (result);
} finally {
RemoveListener (listener);
}
return result;
}
sequence Diagram