Org. JUnit. Runner. Runner is the working engine of JUnit. With the support of many types, it processes the test and generates (description), failure, and result outputs.
The main class hierarchy of the runner.
Describable and runner
To ensure that all runner subclasses have a description (virtual domain mode) Data Source/member variable,Runner implements describable.
package org.junit.runner;public interface Describable {/** * @return a {@link Description} showing the tests to be run by the receiver */public abstract Description getDescription();}
According to the annotations, runner. getdescription () returns the message receiver.
Runner will run the description/test tree of the test. Runner in JUnit is an abstract class,
Package Org. JUnit. runner; import Org. JUnit. runner. notification. runnotifier; public abstract class runner implements describable {// public abstract description getdescription (); // public abstract void run (runnotifier notifier) can be omitted; Public int testcount () {return getdescription (). testcount ();}}
Yqj2065 does not like the cheap testcount () method, or I prefer to design the runner as an interface.
Parentrunner <t>
Sorting and filtering are not discussed at the moment.
The name of parentrunner <t> indicates that this runner is a part of the test tree."Parent node" Runner. However, for the Runner, "parent node" only has a unit test class and a group test class. Therefore, parentrunner <t> has two subtypes: blockjunit4classrunner and suite. Other non-Runner of the parent node, including ignoredclassrunner and errorreportingrunner.
The type parameter t of parentrunner <t>, representing itsA type of child. This is a relativelyChic Design.
Private list <t> ffilteredchildren = NULL;
Protected abstract list <t> getchildren ();
Protected abstract description describechild (TChild );
Protected abstract void runchild (TChild, runnotifier notifier );
Blockjunit4classrunner has no sub-runners for a unit test class.T is frameworkmethod.
For a group test class, suite has several sub-runners,T is runner.
We can see that,The test tree corresponding to the runner is also a Tree StructureWhile a unit test class only has one blockjunit4classrunner.
Runnerscheduler
This interface indicates the time series scheduling policy for running the test method, whether it is sequential execution or parallel. In parentrunner <t>, sequential execution is used by default, so we can see the rareRunnable. Run ().
private RunnerScheduler fScheduler= new RunnerScheduler() {public void schedule(Runnable childStatement) {childStatement.run();}public void finished() {// do nothing}};
You can also set it through public void setscheduler (runnerscheduler Scheduler.
[Junit4.10 source code analysis] 6 runner