Search in sources :

Example 11 with Request

use of org.junit.runner.Request in project junit4 by junit-team.

the class MaxStarterTest method preferFast.

@Test
public void preferFast() {
    Request request = Request.aClass(TwoUnEqualTests.class);
    fMax.run(request);
    Description thing = fMax.sortedLeavesForTest(request).get(1);
    assertEquals(Description.createTestDescription(TwoUnEqualTests.class, "slow"), thing);
}
Also used : Description(org.junit.runner.Description) Request(org.junit.runner.Request) Test(org.junit.Test)

Example 12 with Request

use of org.junit.runner.Request in project junit4 by junit-team.

the class MaxStarterTest method preferRecentlyFailed.

@Test
public void preferRecentlyFailed() {
    Request request = Request.aClass(TwoTests.class);
    fMax.run(request);
    List<Description> tests = fMax.sortedLeavesForTest(request);
    Description dontSucceed = Description.createTestDescription(TwoTests.class, "dontSucceed");
    assertEquals(dontSucceed, tests.get(0));
}
Also used : Description(org.junit.runner.Description) Request(org.junit.runner.Request) Test(org.junit.Test)

Example 13 with Request

use of org.junit.runner.Request in project junit4 by junit-team.

the class MaxStarterTest method correctErrorFromHalfMalformedTest.

@Test
public void correctErrorFromHalfMalformedTest() {
    Request request = Request.aClass(HalfMalformedJUnit38TestMethod.class);
    JUnitCore core = new JUnitCore();
    Request sorted = fMax.sortRequest(request);
    Runner runner = sorted.getRunner();
    Result result = core.run(runner);
    Failure failure = result.getFailures().get(0);
    assertThat(failure.toString(), containsString("MalformedJUnit38TestMethod"));
    assertThat(failure.toString(), containsString("testNothing"));
    assertThat(failure.toString(), containsString("isn't public"));
}
Also used : JUnit38ClassRunner(org.junit.internal.runners.JUnit38ClassRunner) Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 14 with Request

use of org.junit.runner.Request in project junit4 by junit-team.

the class MaxStarterTest method sortTestsInMultipleClasses.

@Test
public void sortTestsInMultipleClasses() {
    Request request = Request.classes(Computer.serial(), TwoTests.class, TwoTests.class);
    fMax.run(request);
    List<Description> tests = fMax.sortedLeavesForTest(request);
    Description dontSucceed = Description.createTestDescription(TwoTests.class, "dontSucceed");
    assertEquals(dontSucceed, tests.get(0));
    assertEquals(dontSucceed, tests.get(1));
}
Also used : Description(org.junit.runner.Description) Request(org.junit.runner.Request) Test(org.junit.Test)

Example 15 with Request

use of org.junit.runner.Request in project nutz by nutzam.

the class AdvancedTestAll method main.

public static void main(String[] args) {
    //得到所有带@Test的方法
    List<Class<?>> list = Scans.me().scanPackage("org.nutz");
    List<Request> reqs = new ArrayList<Request>();
    Map<Request, Method> reqMap = new HashMap<Request, Method>();
    for (Class<?> clazz : list) {
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (method.getAnnotation(Test.class) != null) {
                Request req = Request.method(clazz, method.getName());
                reqs.add(req);
                reqMap.put(req, method);
            }
        }
    }
    System.out.printf("Found %d Test Class\n", reqs.size());
    //先按普通顺序跑一次
    TestResult simpleTestResult = test(reqs, "normal", reqMap);
    //倒序跑一次
    Collections.reverse(reqs);
    TestResult reverseTestResult = test(reqs, "reverse", reqMap);
    //乱序跑3次
    Collections.shuffle(reqs);
    TestResult shuffleTestResult_A = test(reqs, "shuffle_A", reqMap);
    Collections.shuffle(reqs);
    TestResult shuffleTestResult_B = test(reqs, "shuffle_B", reqMap);
    Collections.shuffle(reqs);
    TestResult shuffleTestResult_C = test(reqs, "shuffle_C", reqMap);
    System.out.println("正常顺序------------------------------------------------");
    printResult(simpleTestResult);
    System.out.println("反序------------------------------------------------");
    printResult(reverseTestResult);
    System.out.println("乱序A------------------------------------------------");
    printResult(shuffleTestResult_A);
    System.out.println("乱序B------------------------------------------------");
    printResult(shuffleTestResult_B);
    System.out.println("乱序C------------------------------------------------");
    printResult(shuffleTestResult_C);
    System.out.println("-------------------------------------------------------Done");
}
Also used : HashMap(java.util.HashMap) Test(org.junit.Test) ArrayList(java.util.ArrayList) Request(org.junit.runner.Request) TestResult(junit.framework.TestResult) Method(java.lang.reflect.Method)

Aggregations

Request (org.junit.runner.Request)54 Test (org.junit.Test)37 JUnitCore (org.junit.runner.JUnitCore)32 Result (org.junit.runner.Result)22 Description (org.junit.runner.Description)20 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)8 Runner (org.junit.runner.Runner)8 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 RunListener (org.junit.runner.notification.RunListener)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 Filter (org.junit.runner.manipulation.Filter)5 Failure (org.junit.runner.notification.Failure)5 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4 ArrayList (java.util.ArrayList)3 Computer (org.junit.runner.Computer)3 TestNode (com.google.testing.junit.runner.model.TestNode)2