Netbeans already includes the junit classes. So there is nothing to install.
When creating a project, Netbeans assumes you will have the source .java files in one folder and test class .java files in another folder. E.g. The project folder will generally contain two subfolders src and test.
Netbeans assumes the junit library should be used when compiling and running the test class, but it is not included in libraries used for the files in src.
The Projects tree will contain two nodes for libraries:
[+] Libraries [+] Test Libraries
If you manage to put the test class in the src file along with the class to be tested instead of the in the Test Packages folder (tests), you will need to add the junit library to the Libraries node.
public class BlobTest extends TestCase
Junit.3.8.1 (but not later version 4) contains two different ways to display output: one is just text output, the other is displayed in a graphical user interface.
The main method calls one of two methods depending on whether the text output or the graphical user interface output is desired.
(Replace BlobTest by the actual name of the testing class.) public static void main(String[] args) { junit.textui.TestRunner.run( BlobTest.class ); } public static void main(String[] args) { junit.swingui.TestRunner.run(BlobTest.class); }
assertEquals(expected_value, expression)
assertTrue(boolean_expression)
assertFalse(boolean_expresion)
assertNull(expression)
assertNotNull(expression)
fail()
If an assertXXX method fails in a test method, that test method fails.
If the fail() method is executed, it always fails. It is typically used conditionally. That is, you could write an if statement with one alternative calling fail(). This would be appropriate if that alternative should never happen. A common use is with a try .. catch construct. The catch block is only executed if an exception occurs while the try block is executed completely if no execption occurs.
If some code should throw an exception, you can test it by puting that code in a try block and put a call to fail() also in the try block just after the code. The catch block can have an empty body. If the fail() method is reached, the code did not throw an exception as it should have and the test method fails!
If a test method fails, the remaining test methods are still executed and the output reports for each method whether it succeeded or failed.
If a test failed, further information is given. E.g. if a call to assertEquals fails the expected value and the actual value of the expression are output.