0
Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek
What is Unit Testing <ul><li>Method of testing that verifies the individual units of the code is working properly (Wikiped...
Why Unit Testing <ul><li>Verifies if the unit is working offcourse!   </li></ul><ul><li>Make sure the unit is working eve...
Unit Testing in Java <ul><li>2 most used testing framework in java </li></ul><ul><ul><li>Junit </li></ul></ul><ul><ul><li>...
What is Junit <ul><li>Is a unit test framework in java </li></ul><ul><li>Developed by Kent Beck and Erich Gamma </li></ul>...
Simple JUnit <ul><li>Create test class and test case. </li></ul><ul><li>Use an assert method for ensuring method output </...
Junit in Netbeans 6.1 <ul><li>You don’t need to load the jar into netbeans project. </li></ul><ul><li>By default the jar i...
Lets Do The Code <ul><li>Lets start with heating up our Netbeans 6.1 and create new java project. </li></ul><ul><li>Make a...
SimpleMath.java
Create Unit Test <ul><li>Choose this menu in netbeans </li></ul><ul><ul><li>Tools > Create Junit Test </li></ul></ul><ul><...
Unit Test Menu
Unit Test Window
SimpleMathTest.java
Unit Testing <ul><li>Assign the variable value for the test case. </li></ul><ul><li>Remove the fail() method in return val...
Test Result
Thank You <ul><li>Have a nice unit testing day folks!! </li></ul>
Upcoming SlideShare
Loading in...5
×

Simple Unit Testing With Netbeans 6.1

19,340

Published on

youll see how simple making test class with netbeans 6.1

Published in: Technology, Travel
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
19,340
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
337
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Simple Unit Testing With Netbeans 6.1"

  1. 1. Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek
  2. 2. What is Unit Testing <ul><li>Method of testing that verifies the individual units of the code is working properly (Wikipedia). </li></ul><ul><li>Test the smallest unit in source code </li></ul>
  3. 3. Why Unit Testing <ul><li>Verifies if the unit is working offcourse!  </li></ul><ul><li>Make sure the unit is working even after late changes in source code (regression test) </li></ul><ul><li>Provides living documentation of how the units (e.g Method) works. </li></ul>
  4. 4. Unit Testing in Java <ul><li>2 most used testing framework in java </li></ul><ul><ul><li>Junit </li></ul></ul><ul><ul><li>TestNG </li></ul></ul><ul><li>This time we used Junit because its embedded in netbeans 6.1. </li></ul>
  5. 5. What is Junit <ul><li>Is a unit test framework in java </li></ul><ul><li>Developed by Kent Beck and Erich Gamma </li></ul><ul><li>Widely used and commonly become standard unit test framework </li></ul><ul><li>Is part of xUnit family. xUnit is a ported Junit for various language. </li></ul><ul><ul><li>PHPunit (PHP) </li></ul></ul><ul><ul><li>Nunit(.NET) </li></ul></ul>
  6. 6. Simple JUnit <ul><li>Create test class and test case. </li></ul><ul><li>Use an assert method for ensuring method output </li></ul><ul><ul><li>assertEquals() </li></ul></ul><ul><ul><li>assertTrue() </li></ul></ul><ul><ul><li>assertNotNull() </li></ul></ul><ul><li>Can be invoked manually by running the test class or automated by using ant script </li></ul>
  7. 7. Junit in Netbeans 6.1 <ul><li>You don’t need to load the jar into netbeans project. </li></ul><ul><li>By default the jar is embedded in test libarary folder </li></ul><ul><li>And also netbeans has test class and test case code generation menu </li></ul>
  8. 8. Lets Do The Code <ul><li>Lets start with heating up our Netbeans 6.1 and create new java project. </li></ul><ul><li>Make a simple class having both return valued and void method. </li></ul><ul><li>Let the return valued method do simple process for example addition or substraction. </li></ul><ul><li>Just print something in the void method. </li></ul>
  9. 9. SimpleMath.java
  10. 10. Create Unit Test <ul><li>Choose this menu in netbeans </li></ul><ul><ul><li>Tools > Create Junit Test </li></ul></ul><ul><li>Or just simply press Ctrl + Shift + U. </li></ul><ul><li>A window dialogue will appear, choose suitable options. </li></ul><ul><li>Or you can leave it as is. Like I usually do  . </li></ul><ul><li>Test case will automatically build inside the test package folder. </li></ul>
  11. 11. Unit Test Menu
  12. 12. Unit Test Window
  13. 13. SimpleMathTest.java
  14. 14. Unit Testing <ul><li>Assign the variable value for the test case. </li></ul><ul><li>Remove the fail() method in return valued method test. </li></ul><ul><li>Run the test class using Shift + F6. </li></ul><ul><li>See the test result </li></ul>
  15. 15. Test Result
  16. 16. Thank You <ul><li>Have a nice unit testing day folks!! </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×