simple unit testing with netbeans 6.1
DESCRIPTION
youll see how simple making test class with netbeans 6.1TRANSCRIPT
![Page 1: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/1.jpg)
Simple Java Unit Testing Simple Java Unit Testing with JUnit 4 and Netbeans with JUnit 4 and Netbeans 6.16.1Kiki AhmadiJUG-Bonek
![Page 2: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/2.jpg)
What is Unit TestingWhat is Unit TestingMethod of testing that verifies
the individual units of the code is working properly (Wikipedia).
Test the smallest unit in source code
![Page 3: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/3.jpg)
Why Unit TestingWhy Unit TestingVerifies if the unit is working
offcourse! Make sure the unit is working
even after late changes in source code (regression test)
Provides living documentation of how the units (e.g Method) works.
![Page 4: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/4.jpg)
Unit Testing in JavaUnit Testing in Java2 most used testing framework in
java◦Junit◦TestNG
This time we used Junit because its embedded in netbeans 6.1.
![Page 5: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/5.jpg)
What is JunitWhat is JunitIs a unit test framework in javaDeveloped by Kent Beck and Erich
GammaWidely used and commonly
become standard unit test framework
Is part of xUnit family. xUnit is a ported Junit for various language.◦PHPunit (PHP)◦Nunit(.NET)
![Page 6: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/6.jpg)
Simple JUnitSimple JUnitCreate test class and test case.Use an assert method for
ensuring method output◦assertEquals()◦assertTrue()◦assertNotNull()
Can be invoked manually by running the test class or automated by using ant script
![Page 7: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/7.jpg)
Junit in Netbeans 6.1Junit in Netbeans 6.1You don’t need to load the jar
into netbeans project.By default the jar is embedded in
test libarary folderAnd also netbeans has test class
and test case code generation menu
![Page 8: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/8.jpg)
Lets Do The CodeLets Do The CodeLets start with heating up our
Netbeans 6.1 and create new java project.
Make a simple class having both return valued and void method.
Let the return valued method do simple process for example addition or substraction.
Just print something in the void method.
![Page 9: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/9.jpg)
SimpleMath.javaSimpleMath.java
![Page 10: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/10.jpg)
Create Unit TestCreate Unit TestChoose this menu in netbeans
◦Tools > Create Junit TestOr just simply press Ctrl + Shift +
U.A window dialogue will appear,
choose suitable options.Or you can leave it as is. Like I
usually do .Test case will automatically build
inside the test package folder.
![Page 11: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/11.jpg)
Unit Test MenuUnit Test Menu
![Page 12: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/12.jpg)
Unit Test WindowUnit Test Window
![Page 13: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/13.jpg)
SimpleMathTest.javaSimpleMathTest.java
![Page 14: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/14.jpg)
Unit TestingUnit TestingAssign the variable value for the
test case.Remove the fail() method in
return valued method test.Run the test class using Shift +
F6.See the test result
![Page 15: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/15.jpg)
Test ResultTest Result
![Page 16: Simple Unit Testing With Netbeans 6.1](https://reader035.vdocument.in/reader035/viewer/2022062615/5485c24db47959190d8b4f02/html5/thumbnails/16.jpg)
Thank YouThank You
Have a nice unit testing day folks!!