Test cases in inner classes with JUnit

前端 未结 5 614
故里飘歌
故里飘歌 2020-12-02 12:09

I read about Structuring Unit Tests with having a test class per class and an inner class per method. Figured that seemed like a handy way to organize the tests, so I tried

5条回答
  •  [愿得一人]
    2020-12-02 12:35

    I think some of the answers might be for older versions of JUnit. In JUnit 4 this worked for me:

        @RunWith(Suite.class)
        @Suite.SuiteClasses({ DogTests.BarkTests.class, DogTests.EatTests.class })
        public class DogTests
        {
            public static class BarkTests
            {
                @Test
                public void quietBark_IsAtLeastAudible() { }
    
                @Test
                public void loudBark_ScaresAveragePerson() { }
            }
    
            public static class EatTests
            {
                @Test
                public void normalFood_IsEaten() { }
    
                @Test
                public void badFood_ThrowsFit() { }
            }
        }
    

提交回复
热议问题