apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.63k stars 841 forks source link

Support Junit @Nested test classes #3975

Open ratcashdev opened 2 years ago

ratcashdev commented 2 years ago

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

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.

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?

Code of Conduct

ratcashdev commented 2 years ago

Applies to MAVEN projects too.

ratcashdev commented 2 years ago

PR is waiting for review. Please have a look on it.

dstutz commented 1 month ago

What happened to this?