question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Enclosed runner not try to run the tests in static nested classes without test methods

See original GitHub issue

The Enclosed runner treats all static nested classes as test classes. If any static nested classes have no methods annotated with @Test you will get a failure. This prevents you from having a nested class that is a helper class. It would be great if Enclosed would ignore those classes.

Suggestion: Make Enclosed runner ignore all the inner classes annotated with @Ignore just like it works for ignoring the tests with @Ignore.

@RunWith(Enclosed.class)
public class RootTest {

  @Ignore
  public static class B {
    ......
  }

  public static class FooTest {
    @Test
    public void testFoo() {
      B b = new B();
      ....
    }
  }
}

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
adrianosimoescommented, Jan 27, 2017

I tried this with JUnit 4.11 and I didn’t got any error if I put the @Ignore on the B class. Probably fixed already.

@RunWith(Enclosed.class)
public class Test {
     @Ignore
     public static class B {
           public static void test() {}
     }
     public static class FooTest {
       @Test
       public void testFoo() {
        B.test();
       }
     }
   }
0reactions
marcphilippcommented, Jul 26, 2022

Thanks for the feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

how can I use @Enclosed without making methods as static
Unfortunately, the Enclosed runner requires that the enclosed classes be static (aka "nested classes").
Read more >
Running non-static inner classes of JUnit tests
Running non -static inner classes of JUnit tests. JUnit ships with an "experimental" custom runner called Enclosed . When you annotate a test...
Read more >
JUnit5 inner test classes should be annotated with @Nested
This rule raises an issue on inner classes and static nested classes containing JUnit5 test methods which has a wrong usage of @Nested...
Read more >
JUnit 5 Tutorial: Writing Nested Tests - Petri Kainulainen
This blog post describes how we can write nested tests with JUnit 5. ... All nested test classes must be non-static inner classes....
Read more >
Testing - Spring
The POJOs that make up your application should be testable in JUnit or TestNG tests, with objects instantiated by using the new operator, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found