Skip to content

Support Junit @Nested test classes #3975

@ratcashdev

Description

@ratcashdev

Description

original ticket: https://issues.apache.org/jira/browse/NETBEANS-6041

Given a test class like:

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

public class SampleTest {
  @Test
  public void testMyMethod1() {
    System.out.println("write this");
  }
  @Nested
  class NestedClass {
    @Test
    public void testMyMethod2() {
      System.out.println("nested write 2");
    }
  }
  @Nested
  class NestedClass2 {
    @Test
    public void testMyMethod1() {
      System.out.println("nested write 1");
    }
    @Test
    public void testMyMethod3() {
      System.out.println("nested write 3");
    }
    @Nested
    class DoubleNestedClass3 {
      @Test
      public void testMyMethod4() {
        System.out.println("double nested write 4");
      }
      @Test
      public void testNextedException() throws Exception {
        throw new Exception();
      }
    }
  }
}

we have two major issues:

  1. The "Test Results" window shows only some of the executed tests (in this specific case only 3)
  2. using the "Run focused test method" does not work - a bad combo of class and method is provided to the test runner.

Did some root-cause analysis too. The issue with Tests not showing is caused by the fact that the whole testrunner support was made with the assumption that test suites are executed sequentially. This, unfortunately is not true with nested tests, where the execution may look like

  • A$B.method1
  • A.method2
  • A$B.method3
  • A.method4

Fixing this needs significant changes to TestSession and TestProgressListener which assume that only one suite can be running at any given time (and thus measures the elapsed time).

It works somewhat if tests are only on equal level, e.g.

  • A$B.method1
  • A$B.method2
  • A$C.method3
  • A$C.method4

If there was a method directly on A, like A.otherMethod, then the results would not be shown again.

Use case/motivation

Work with such classes without issues

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Gradle[ci] enable "build tools" testsMaven[ci] enable "build tools" testskind:featureA feature requesttests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions