[Junit4.10 source code analysis] 6 runner

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.