Netbeans: "Run -> Test Project" doesn't do anything
Asked Answered
D

4

7

I have many JUnit tests, which are all created by Netbeans' assistant (so nothing customized). I can run every test manually by doing "Test File" (Ctrl+F6).

But when I use "Run -> Test Project", the message "No Tests executed" is displayed.

Do I have to register every JUnit test somewhere?
Or what could be the problem here?

Before that, following appears in the output window:

init:
Deleting: /MY-WORK/my.data.adv/build/built-jar.properties
deps-jar:
Updating property file: /MY-WORK/my.data.adv/build/built-jar.properties
my.commons.init:
my.commons.deps-jar:
Updating property file: /MY-WORK/my.data.adv/build/built-jar.properties
my.commons.compile:
Copy libraries to /MY-WORK/my.commons/dist/lib.
my.commons.jar:
my.data.init:
my.data.deps-jar:
Updating property file: /MY-WORK/my.data.adv/build/built-jar.properties
my.data.compile:
Copy libraries to /MY-WORK/my.data/dist/lib.
my.data.jar:
compile:
compile-test:
test-report:
test:
BUILD SUCCESSFUL (total time: 0 seconds)

EDIT

  • The project type is "class library", no custom configurations in build.xml are used.

  • Perhaps it is relevant to mention, that the project is old (created with some Netbeans version prior to 6.7).

Deferred answered 2/3, 2010 at 19:59 Comment(5)
What type of project exactly? (Desktop, Web, other)Hubsher
how did you name the class files and where did you put the files?Nielson
Everything is classic: JUnit tests are in package folder "test" (label "Test Packages"). JUnit tests are in package, which has same name as that of the classes under test.Deferred
when I have run into this with NB 6.8,it was due to the following reason... The JUnit tests are not in a file named *Test.java.Kristeenkristel
@vkraemer: You're right! Please write this as an answer so I can mark it correct! I have found the following in the build-impl.xml: <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run"> <j2seproject3:junit testincludes="**/*Test.java"/> </target>Deferred
K
9

Since I submitted the correct clue necessary to generate an answer, I figure that I should add a bit of value to it...

If you create a Java->Class Library project with NetBeans, you can create a unit test associated with each of the classes in your project's Source Packages. You just need to right-click on the class in the Projects explorer.

If you are creating the 'first test' for a project, the IDE lets you choose between JUnit 3 and JUnit 4.

When you create a test for a.b.c.NewClass, NetBeans will allow you to name the test anything you want and put the test in any package you want... most of the time, you do not want to change the defaults that appear in the dialog (a.b.c.NewClassTest). In NetBeans 6.9 builds, a warning will appear if the name of the test you are about to create does not have "Test" as its suffix.

If you create test class names that do not end with "Test", you can still get them to run when you use the Test action on a project. You just have to trigger them from a 'normal' test class.

Kristeenkristel answered 3/3, 2010 at 0:30 Comment(0)
D
8

Thanks to the user vkraemer!

The solution is: Only JUnit tests are run when their name ends with Test.

Section from build-impl.xml proves it:

<target depends="init,compile-test,-pre-test-run"
    if="have.tests" name="-do-test-run">
  <j2seproject3:junit testincludes="**/*Test.java"/>
</target>
Deferred answered 2/3, 2010 at 21:12 Comment(0)
M
2

If you are using maven, you might want to check your surefire plugin on pom.xml

...
 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.11</version>
            <configuration>
                <includes>
                    <include>**/*Test.java</include>                        
                </includes>
                <systemPropertyVariables>
                    <java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
                </systemPropertyVariables>
            </configuration>
        </plugin>


  ...
Monkeypot answered 20/11, 2013 at 21:37 Comment(1)
I would agree that this is a pointer into the right direction - also check that maybe there is a parent POM that specifies <skipTests>true</skipTests> in its surefire plugin configurationLentissimo
I
0

My tests were working then they stopped, just displaying:

No tests executed.(0.0 s)

The problem was an extra space in the VM Options: after the -D. This caused problems:

-D mysetting.home=something

and this fixed it:

-Dmysetting.home=something
Incurable answered 3/6, 2010 at 15:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.