Run tests from inner classes via Maven

前端 未结 2 1747
感情败类
感情败类 2021-02-19 23:25

I have following tests structure:

public class WorkerServiceTest {

    public class RaiseErrorTest extends AbstractDbUnitTest{
        @Test
        public void         


        
2条回答
  •  心在旅途
    2021-02-19 23:57

    Yes, this is possible using the new (well, it's not new anymore) Enclosed runner (since JUnit 4.5) that runs all static inner classes of an outer class.

    To use it, just annotate the outer class with @RunWith(Enclosed.class) and make the inner classes static.

    @RunWith(Enclosed.class)
    public class WorkerServiceTest {
    
        public static class RaiseErrorTest extends AbstractDbUnitTest{
            @Test
            public void testSomething(){
            } 
    
            ...
        }
    
        ...
    }
    

    And mvn test will run them.

提交回复
热议问题