netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Java with Ant - JUnit Bug

Open antoniojvelezq opened this issue 1 year ago • 3 comments

Apache NetBeans version

Apache NetBeans 23

What happened

I created a simple unit test, but it generates the following error when running the test:

/home/ajvelez/.cache/netbeans/23/executor-snippets/junit.xml:184: The following error occurred while executing this line: /home/ajvelez/.cache/netbeans/23/executor-snippets/junit.xml:128: The or for must include junit.jar if not in Ant's own classpath

Language / Project Type / NetBeans Component

Java / Java with Ant / JUnit execute

How to reproduce

Create a Java with Ant y execute the next test

public class NewEmptyJUnitTest {
    
    public NewEmptyJUnitTest() {   }

     @Test
     public void hello() {
         assertEquals(20, 20);
     }
}

Did this work correctly in an earlier version?

No / Don't know

Operating System

Fedora 40

JDK

JDK17 and JDK22

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

antoniojvelezq avatar Oct 01 '24 19:10 antoniojvelezq

Where is the reproducer for the problem?

matthiasblaesing avatar Oct 01 '24 19:10 matthiasblaesing

Create a Java with Ant project, and execute the next test.

public class NewEmptyJUnitTest {
public NewEmptyJUnitTest() {   }
 @Test public void hello() {
     assertEquals(20, 20);
 }
}

antoniojvelezq avatar Oct 01 '24 19:10 antoniojvelezq

@antoniojvelezq you could have simplified this by just providing the project. Anyway, yes, the projects seems to be incorrectly generated, as JUnit 5 is put onto the classpath.

matthiasblaesing avatar Oct 01 '24 19:10 matthiasblaesing

The following scenario reproduces the error.

New Project -> Java with Ant -> Java Application. choose location and name.

generated by my choices


package puk;

public class Puk {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }

}

Add test for existing class. Generated is a test class with references to junit 5:

package puk;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class PukTest {

    public PukTest() {
    }

    @Test
    public void testSomeMethod() {
        fail("puk");
    }

}

The libraries are loaded, fitting to this choice of junit.

Image

However, trying to run the test produces

Image

It appears that the build-impl.xml is not prepared to use junit 5 tests.

homberghp avatar Jul 03 '25 07:07 homberghp