JUNIT4 's entry Class-Junitcore__junitcore

Source: Internet
Author: User
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


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.