How to use runClasses method of org.junit.runner.JUnitCore class

Best junit code snippet using org.junit.runner.JUnitCore.runClasses

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package tests;
2/**
3 * This class is used to run test tests.
4 * @author Aqib Rashid
5 */
6
7import org.junit.runner.JUnitCore;
8import org.junit.runner.Result;
9import org.junit.runner.notification.Failure;
10
11import model.*;
12
13public class TestRunner {
14	public static void main(String[] args) {
15		Result result = JUnitCore.runClasses(BasicComputerPlayerTest.class);
16		for (Failure failure : result.getFailures()) {
17			System.out.println(failure.toString());
18		}
19		System.out.println(result.wasSuccessful());
20		
21		
22		result = JUnitCore.runClasses(BoardTest.class);
23		for (Failure failure : result.getFailures()) {
24			System.out.println(failure.toString());
25		}
26		System.out.println(result.wasSuccessful());
27		
28		result = JUnitCore.runClasses(HouseTest.class);
29		for (Failure failure : result.getFailures()) {
30			System.out.println(failure.toString());
31		}
32		System.out.println(result.wasSuccessful());
33		
34		result = JUnitCore.runClasses(PlayerTest.class);
35		for (Failure failure : result.getFailures()) {
36			System.out.println(failure.toString());
37		}
38		System.out.println(result.wasSuccessful());
39		
40		result = JUnitCore.runClasses(ScoreHouseTest.class);
41		for (Failure failure : result.getFailures()) {
42			System.out.println(failure.toString());
43		}
44		System.out.println(result.wasSuccessful());
45		
46		result = JUnitCore.runClasses(SeedTest.class);
47		for (Failure failure : result.getFailures()) {
48			System.out.println(failure.toString());
49		}
50		System.out.println(result.wasSuccessful());
51		
52
53	}
54}
55
Full Screen
copy
1import org.junit.runner.JUnitCore;
2import org.junit.runner.Result;
3import org.junit.runner.notification.Failure;
4
5import java.util.ArrayList;
6import java.util.Arrays;
7import java.util.List;
8
9public class xtest {
10
11  public static void main(String[] args) {
12    Result result1 = JUnitCore.runClasses(BoardTest.class);
13    Result result2 = JUnitCore.runClasses(FishModelTest.class);
14    Result result3 = JUnitCore.runClasses(GameNodeTest.class);
15    Result result4 = JUnitCore.runClasses(InternalPlayerTest.class);
16    Result result5 = JUnitCore.runClasses(PenguinTest.class);
17    Result result6 = JUnitCore.runClasses(PlayerTest.class);
18    Result result7 = JUnitCore.runClasses(Pos2DTest.class);
19    Result result8 = JUnitCore.runClasses(RefereeTest.class);
20    Result result9 = JUnitCore.runClasses(StrategyTest.class);
21    Result result10 = JUnitCore.runClasses(xBoardTest.class);
22    Result result11 = JUnitCore.runClasses(xStateTest.class);
23    Result result12 = JUnitCore.runClasses(xTreeTest.class);
24    Result result13 = JUnitCore.runClasses(PieceTest.class);
25    Result result14 = JUnitCore.runClasses(ManagerTest.class);
26
27    List<Result> allTests = new ArrayList<>(Arrays.asList(result1, result2, result3, result4, result5,
28            result6, result7, result8, result9,result10,result11, result12, result13, result14));
29
30    for (Result result : allTests) {
31      for (Failure failure : result.getFailures()) {
32        System.out.println(failure.toString());
33      }
34    }
35
36    int totalCount = 0;
37    for (Result result: allTests) {
38      totalCount += result.getRunCount();
39    }
40
41    int totalFailCount = 0;
42    for (Result result: allTests) {
43      totalFailCount += result.getFailureCount();
44    }
45
46    int totalRunTime = 0;
47    for (Result result: allTests) {
48      totalRunTime += result.getRunTime();
49    }
50
51    System.out.println("Number of tests run: " + totalCount);
52    System.out.println("Number of failed tests: " + totalFailCount);
53    System.out.println("Runtime: " + totalRunTime);
54    System.exit(0);
55  }
56}
57
Full Screen
copy
1package test.lille1.car2014.durieux_toulet;
2
3import org.junit.runner.JUnitCore;
4import org.junit.runner.Result;
5import org.junit.runner.notification.Failure;
6import test.lille1.car2014.durieux_toulet.entity.BookImplTest;
7import test.lille1.car2014.durieux_toulet.entity.OrderImplTest;
8import test.lille1.car2014.durieux_toulet.entity.UserImplTest;
9import test.lille1.car2014.durieux_toulet.manager.BookManagerTest;
10import test.lille1.car2014.durieux_toulet.manager.UserManagerTest;
11
12/**
13 * @author Toulet Cyrille
14 */
15public class JUnitRunner {
16
17  /**
18   * Main
19   *
20   * @param args
21   */
22  public static void main(final String[] args) {
23    // Test BookManager
24    Result result = JUnitCore.runClasses(BookManagerTest.class);
25
26    for (final Failure failure : result.getFailures()) {
27      System.out.println(failure.toString());
28    }
29
30    /* Test UserManager */
31    result = JUnitCore.runClasses(UserManagerTest.class);
32
33    for (final Failure failure : result.getFailures()) {
34      System.out.println(failure.toString());
35    }
36
37    /* Test BookImpl */
38    result = JUnitCore.runClasses(BookImplTest.class);
39
40    for (final Failure failure : result.getFailures()) {
41      System.out.println(failure.toString());
42    }
43
44    /* Test OrderImpl */
45    result = JUnitCore.runClasses(OrderImplTest.class);
46
47    for (final Failure failure : result.getFailures()) {
48      System.out.println(failure.toString());
49    }
50
51    /* Test UserImpl */
52    result = JUnitCore.runClasses(UserImplTest.class);
53
54    for (final Failure failure : result.getFailures()) {
55      System.out.println(failure.toString());
56    }
57  }
58}
59
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in JUnitCore

Trigger runClasses code on LambdaTest Cloud Grid

Execute automation tests with runClasses on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)