JUnit test for inner static class

I have a testing class like this:

<code>

 
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ClassOuterTest {
   @Test
   public void
testOuter() {
      assertEquals(1, 0, 0);
   }

   public static class ClassInnerTest {
      @Test
      public void
testInner() {
         assertEquals(1, 0, 0);
      }
   }
}
 
</code>


Right now the inner class test is not run when the outer class test is called via Run/Debug. Is there a possibility to force this by Configuration/Annotation or do I have to create a run target for this inner class separately?

2 comments
Comment actions Permalink

Hi Thomas,

as far as I understand junit doesn't run inner classes by default. Why do you need this configuration?

Thanks

0
Comment actions Permalink

Hi Anna,

I simply wanted to know if I need to declare a specific test class for any static inner class separately. It is obviously the case.

There are some answers in Stackoverflow which give some solutions recommendations but it looks like it is not as simple:

http://stackoverflow.com/questions/8758294/test-cases-in-inner-classes-with-junit

The approach over there uses a mixture of inheritance with overriding constructors and annotations. But this is a bit to much IMHO. So I was wondering if there is a different standard way. Of course in the end I could try to avoid static inner classes. ;-)

Have a nice day
Thomas

0

Please sign in to leave a comment.