I'm using Netbeans 6.8 and the finest-grained way to run my JUnit tests from the IDE appears to be to right-click a class under Test Packages
and click Test File
In Eclipse it's possible to narrow the scope to testing 开发者_Go百科an individual method in a given test harness. How do I test only one individual test out of a harness in Netbeans?
In NetBeans 7.1, open the unit test file, right click within the specific unit test and select "Run Focused Test."
UPDATE: NetBeans supports this (e.g. see NetBeans 6.8). Just right click the passed or failed test and then click 'Run Again' or 'Debug'. Or right click in the editor and click Run/Debug focused test.
Old:
To my knowledge this is not possible. And maybe the NetBeans-guys had in mind that always all tests should pass for one unit. I know that tools should not limit the developers, but If one method takes too long - maybe you should consider a separate integration test?
Also take a look at this post. (BTW: in maven projects running tests of a unit is possible ...)
Netbeans 7.1 "Run Focused Test" isn't working with my build, so I'm using use a test group to mark the tests I want to run.
@Test(groups={"DEBUG"})
You can configure Netbeans to run these tests by adding -Dgroups=DEBUG
to your "Debug Test File" action in the project properties.
Note: these are TestNG methods run with maven/surefire.
Incase anyone is wondering focus testing is also possible via IntelliJ by right click on a specific test and run
The option "Run Focused Test" was grayed-out on my project because there was no action named "run.single.method" in project.xml.
Workaround to get it working:
1) create new "run.single.method" action in project.xml file (you could copy "run.single" action).
project.xml fragment:
<action name="run.single.method">
<script>nbproject/ide-file-targets.xml</script>
<target>run.single.method</target>
<context>
<property>run.class</property>
<folder>test/src</folder>
<pattern>\.java$</pattern>
<format>java-name</format>
<arity>
<one-file-only/>
</arity>
</context>
</action>
2) create new "run.single.method" target in ide-file-targets.xml (you could copy "run-selected-file-in-src") and make sure the test tag has a parameter "methods" using the property "${method}".
ide-file-targets.xml fragment:
<target name="run.single.method" depends="compile">
<fail unless="run.class">Must set property 'run.class'</fail>
<junit maxmemory="256m" fork="true" haltonerror="true" haltonfailure="true" printsummary="on" jvm="${jdk.dir}/bin/java" showoutput="true">
<sysproperty key="build.basedir" value="${basedir}"/>
<!-- method attribute makes the selected method to be unit tested only -->
<test name="${run.class}" methods="${method}"/>
<formatter type="plain" usefile="false"/>
<classpath refid="CLASSPATH"/>
</junit>
</target>
Now you can use the right mouse menu "Run focused test".
The option "Run focused test" might also be temporary be grayed-out when the project is scanning
精彩评论