Testing a method instead of testing a whole file in Netbeans w/ JUnit

12,726

Solution 1

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 ...)

Solution 2

In NetBeans 7.1, open the unit test file, right click within the specific unit test and select "Run Focused Test."

Solution 3

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.

Share:
12,726
Maciek
Author by

Maciek

Updated on June 03, 2022

Comments

  • Maciek
    Maciek almost 2 years

    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 an individual method in a given test harness. How do I test only one individual test out of a harness in Netbeans?

  • Maciek
    Maciek about 14 years
    Thanks for coming back and updating this :)
  • Karussell
    Karussell about 14 years
    no problem. as a netbeans user this bothered me too. is this working for you? it seems to be only available for maven projects!?
  • Andez
    Andez over 11 years
    Did you ever get this working Roger? All of a sudden, my project will not run focused tests - I am not sure why - we have a few developers on the project (including writing JUnit tests). But the test I have done will not run. I'm using Netbeans 7.1.2
  • Roger Keays
    Roger Keays over 11 years
    Yes, I'm using a @Test(groups={DEBUG}) to run individual tests. I setup NetBeans to use -Dgroups=DEBUG and when I run "Debug Test File". It works well and I also add other system properties for debugging (e.g. browser=chrome). Note the groups attribute is for TestNG. JUnit has it's own grouping annotations. But yeh, my Netbeans doesn't run focused tests out of the box - I thought it was because I use inner classes for my test cases (ninthavenue.com.au/how-to-use-inner-classes-for-your-unit-t‌​ests).
  • james.garriss
    james.garriss about 9 years
    This is still true in NB 8.
  • Dinushika Rathnayake
    Dinushika Rathnayake about 2 years
    Right click on the editor and click Run/Debug Focused Test Method not work for me for gradle project in Netbeans 13.