How to run entire JUnit Test Suite from within code

前端 未结 3 404
北荒
北荒 2021-01-13 18:19

In eclipse, with JUnit 4, you can right click a project or package and click Run as JUnit Test, and it will run all the JUnit tests within that grouping. Is there a way to d

3条回答
  •  Happy的楠姐
    2021-01-13 18:46

    JUnit provides the test Suite. Give that a try.

    [...]
    public class TestCaseA {
        @Test
        public void testA1() {
            // omitted
        }
    }
    
    [...]
    public class TestCaseB {
        @Test
        public void testB1() {
            // omitted
      }
    }
    
    [...]
    @RunWith(value=Suite.class)
    @SuiteClasses(value = {TestCaseA.class})
    public class TestSuiteA {
    }
    
    [...]
    @RunWith(value=Suite.class)
    @SuiteClasses(value = {TestCaseB.class})
    public class TestSuiteB {
    }
    
    [...]
    @RunWith(value = Suite.class )
    @SuiteClasses(value = {TestSuiteA.class, TestSuiteB.class})
    public class MasterTestSuite{
    }
    

提交回复
热议问题