Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-5371

The generated JUnit 5 code from the Ant project cannot be run.

    XMLWordPrintableJSON

Details

    Description

      Hello,

      I created a simple class.

      public class Example  {
      
          public static void main(String[] args) {
              var color = new Example();
              System.out.println(color.isTextBlack("black"));
              System.out.println(color.isTextBlack("white"));
          }
      
          public boolean isTextBlack(String color) {
              return color.equals("black");
          }
      }
      

      Then I create a JUnit 5 test via a "bulb" on the class line.

      A file with this code will be generated.

      import org.junit.jupiter.api.AfterEach;
      import org.junit.jupiter.api.AfterAll;
      import org.junit.jupiter.api.BeforeEach;
      import org.junit.jupiter.api.BeforeAll;
      import org.junit.jupiter.api.Test;
      import static org.junit.jupiter.api.Assertions.*;
      
      public class ExampleTest {
          
          public ExampleTest() {
          }
          
          @BeforeAll
          public static void setUpClass() {
          }
          
          @AfterAll
          public static void tearDownClass() {
          }
          
          @BeforeEach
          public void setUp() {
          }
          
          @AfterEach
          public void tearDown() {
          }
      
          /**
           * Test of main method, of class Example.
           */
          @Test
          public void testMain() {
              System.out.println("main");
              String[] args = null;
              Example.main(args);
              // TODO review the generated test code and remove the default call to fail.
              fail("The test case is a prototype.");
          }
      
          /**
           * Test of isTextBlack method, of class Example.
           */
          @Test
          public void testIsTextBlack() {
              System.out.println("isTextBlack");
              String color = "";
              Example instance = new Example();
              boolean expResult = false;
              boolean result = instance.isTextBlack(color);
              assertEquals(expResult, result);
              // TODO review the generated test code and remove the default call to fail.
              fail("The test case is a prototype.");
          }
      }
      

      If I run it, it will crash with this error

      warning: unknown enum constant Status.STABLE
        reason: class file for org.apiguardian.api.API$Status not found
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      warning: unknown enum constant Status.STABLE
      100 warnings
      only showing the first 100 warnings, of 124 total; use -Xmaxwarns if you would like to see more
      

      If I delete the file and create Junit 4 (see the picture above), the same code will be generated, only with the import of other libraries.

      import org.junit.After;
      import org.junit.AfterClass;
      import org.junit.Before;
      import org.junit.BeforeClass;
      import org.junit.Test;
      import static org.junit.Assert.*;

      JUnit 4 works without any problems. The mystery is that if I now delete the file and create JUnit 5, JUnit4 will be created again.

      Anyway, JUnit5 is unusable.

      Please repair.

      Thank you

      Attachments

        1. obr.png
          9 kB
          Michal Rama
        2. obr�zek53.png
          13 kB
          Michal Rama

        Activity

          People

            Unassigned Unassigned
            Michal_cat Michal Rama
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: