Junit4.8.2 source code analysis-3.2 computer

Source: Internet
Author: User

This series of articles record the process of yqj2065 reading the source code of JUnit. Many times there are many things I don't understand in the reading process, such as what a class is doing and why it is needed, why not design it like this ...... And so on.

Org. JUnit. Runner is the core package of JUnit.Computer/computer (is this translation)What does it mean? I didn't understand it when I first started reading junitcore.

package org.junit.runner;import org.junit.runners.Suite;import org.junit.runners.model.InitializationError;import org.junit.runners.model.RunnerBuilder;import org.junit.runner.Runner;/** * Represents a strategy for computing runners and suites. * WARNING: this class is very likely to undergo serious changes in version 4.8 and * beyond. */public class Computer {/** * Returns a new default computer, which runs tests in serial order */public static Computer serial() {return new Computer();}/** * Create a suite for {@code classes}, building Runners with {@code builder}. * Throws an InitializationError if Runner construction fails */public Runner getSuite(final RunnerBuilder builder,Class<?>[] classes) throws InitializationError {return new Suite(new RunnerBuilder() {@Overridepublic Runner runnerForClass(Class<?> testClass) throws Throwable {return getRunner(builder, testClass);}}, classes);}/** * Create a single-class runner for {@code testClass}, using {@code builder} */protected Runner getRunner(RunnerBuilder builder, Class<?> testClass) throws Throwable {return builder.runnerForClass(testClass);}}
In fact, if you call it RunnerfactoryIn seconds.

Furthermore, if you do not consider its subclass org. JUnit.Experimental. parallelcomputerYou can define the two methods of the computer as static.

What a standard static factory is.

Another question is, why is the relationship between the computer and org. JUnit. Runners. model. runnerbuilder used rather than the inheritance relationship? Is the computer only used as the front-end of runnerbuilder?


In short, in the current stage, I think of computer as a factory.




Junit4.8.2 source code analysis-3.2 computer

Related Article

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.