JUnit 4 Tutorials (junit 4 tutorial) Five, test suite

Source: Internet
Author: User
Tags arithmetic assert
Junit 4 allows you to run test classes in bulk by using test suite classes. To create a test suite for a set of test classes, add the following annotations for the test class:
@RunWith (Suite.class) @SuiteClasses (Testclass1.class, Testclass2.class)

When run, all test classes contained within the @suiteclasses annotation are executed. Junit 4 test suite Sample

In this case, Arithmetictest.java and Geometrictest.java will be executed with the JUnit test suite class Alltest.java

Arithmetic.java

Package in.co.javatutorials;
 
/**
* @author javatutorials.co.in * * Public
class arithmetic {public
 
    int Add (int i, int j) {return
        I + j;
    }
}

Geometric.java

Package in.co.javatutorials;
 
/**
* @author javatutorials.co.in
*
/public class Geometry {public
 
    int squarearea (int length) { C16/>return length * length;
    }
}

Arithmetictest.java

Package in.co.javatutorials;
 
Import static org.junit.assert.*;
 
Import Org.junit.Test;
 
/**
* @author javatutorials.co.in
*
/public class Arithmetictest {
    @Test public
    void Testadd () {
        arithmetic arithmetic = new arithmetic ();
        int actualresult = Arithmetic.add (1, 2);
        int expectedresult = 3;
        Assertequals (Expectedresult, Actualresult);
    }

Geometrictest.java

Package in.co.javatutorials;
 
Import static org.junit.assert.*;
 
Import Org.junit.Test;
 
/**
* @author javatutorials.co.in */public
class Geometrytest {
 
    @Test public
    void Testsquarearea () {
        Geometry Geometry = new Geometry ();
        int actualresult = Geometry.squarearea (2);
        int expectedresult = 4;
        Assertequals (Expectedresult, Actualresult);
    }

Alltests.javaTest Suite Class

Package in.co.javatutorials;
 
Import Org.junit.runner.RunWith;
Import Org.junit.runners.Suite;
Import org.junit.runners.Suite.SuiteClasses;
 
/**
* @author javatutorials.co.in * *
@RunWith (suite.class)
@SuiteClasses ({ Arithmetictest.class, Geometrytest.class}) public
class Alltests {
 
}

result Output



Source Download

Click My download source
Tutorial Directory Navigation
Introduction to the JUnit test framework Junit Eclipse Tutorial Junit 4 Annotations Junit 4 Assertion Method (Assert methods) Junit 4 Parameterized testing Junit 4 Testing Suite ( test suite) Junit 4 Ignore test (Ignoretest) Junit 4 Timeout test (Timeout test)

--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------this source for Http://blog.csdn.net/luanlouis, reproduced please indicate the source, thank you.


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.