SlideShare a Scribd company logo
Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek
What is Unit Testing Method of testing that verifies the individual units of the code is working properly (Wikipedia). Test the smallest unit in source code
Why Unit Testing Verifies 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.
Unit Testing in Java 2 most used testing framework in java Junit TestNG This time we used Junit because its embedded in netbeans 6.1.
What is Junit Is a unit test framework in java Developed by Kent Beck and Erich Gamma Widely 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)
Simple JUnit Create 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
Junit in Netbeans 6.1 You don’t need to load the jar into netbeans project. By default the jar is embedded in test libarary folder And also netbeans has test class and test case code generation menu
Lets Do The Code Lets 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.
SimpleMath.java
Create Unit Test Choose this menu in netbeans Tools > Create Junit Test Or 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.
Unit Test Menu
Unit Test Window
SimpleMathTest.java
Unit Testing Assign 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
Test Result
Thank You Have a nice unit testing day folks!!

More Related Content

PPSX
PPT
PPT
05 junit
PPTX
Introduction to JUnit
PPTX
JUNit Presentation
PPTX
JUnit- A Unit Testing Framework
PPTX
PPTX
Java Unit Testing
05 junit
Introduction to JUnit
JUNit Presentation
JUnit- A Unit Testing Framework
Java Unit Testing

What's hot (20)

PPT
JUnit 4
PDF
Unit testing with JUnit
PPTX
Unit Testing with JUnit4 by Ravikiran Janardhana
PPS
JUnit Presentation
PDF
Unit testing with JUnit
ODP
Testing In Java
PDF
PPT
PDF
Test driven development - JUnit basics and best practices
PPTX
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
PPTX
Introduction To J unit
PPTX
Unit Testing in Java
PDF
What is JUnit? | Edureka
PPTX
Testing with Junit4
PPT
PDF
Unit testing with Junit
PPT
Junit and testNG
PPT
3 j unit
PPS
Why Unit Testingl
JUnit 4
Unit testing with JUnit
Unit Testing with JUnit4 by Ravikiran Janardhana
JUnit Presentation
Unit testing with JUnit
Testing In Java
Test driven development - JUnit basics and best practices
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Introduction To J unit
Unit Testing in Java
What is JUnit? | Edureka
Testing with Junit4
Unit testing with Junit
Junit and testNG
3 j unit
Why Unit Testingl
Ad

Viewers also liked (12)

PDF
PPTX
Web Application and HTML Summary
PPTX
Developing Java EE applications with NetBeans and Payara
PPTX
GUI Programming in JAVA (Using Netbeans) - A Review
PPTX
Introduction to java netbeans
PPSX
Basic of Java Netbeans
PPTX
Introduction to Java programming - Java tutorial for beginners to teach Java ...
PPT
GUI Programming In Java
PDF
CBSE XII Communication And Network Concepts
PDF
CBSE XII Boolean Algebra
PPT
BASIC CONCEPTS OF COMPUTER NETWORKS
PPTX
Introduction to computer network
Web Application and HTML Summary
Developing Java EE applications with NetBeans and Payara
GUI Programming in JAVA (Using Netbeans) - A Review
Introduction to java netbeans
Basic of Java Netbeans
Introduction to Java programming - Java tutorial for beginners to teach Java ...
GUI Programming In Java
CBSE XII Communication And Network Concepts
CBSE XII Boolean Algebra
BASIC CONCEPTS OF COMPUTER NETWORKS
Introduction to computer network
Ad

Similar to Simple Unit Testing With Netbeans 6.1 (20)

PPTX
8-testing.pptx
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
DOCX
JUnit_Guide_Expanded_Presentation[1].docx............................
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
PPTX
Junit and cactus
PPTX
Junit Test Cases
PDF
ikp321-04
PPTX
Jack borden jb471909_junit
PPTX
Jack borden jb471909_junit1
PPS
J unit presentation
PDF
junit-160729073220 eclipse software testing.pdf
DOCX
Test Driven Development
PPT
Testing Options in Java
PDF
J unit a starter guide
PPT
Google test training
PDF
SE2_Lec 21_ TDD and Junit
PDF
Introduction to test automation in java and php
PDF
JUnit Testing Framework A Complete Guide.pdf
PPTX
Unit Testing in .NET Core 7.0 with XUnit.pptx
PDF
Unit testing in Unity
8-testing.pptx
JUnit_Guide_Expanded_Presentation[1].docx
JUnit_Guide_Expanded_Presentation[1].docx............................
JUnit_Guide_Expanded_Presentation[1].docx
Junit and cactus
Junit Test Cases
ikp321-04
Jack borden jb471909_junit
Jack borden jb471909_junit1
J unit presentation
junit-160729073220 eclipse software testing.pdf
Test Driven Development
Testing Options in Java
J unit a starter guide
Google test training
SE2_Lec 21_ TDD and Junit
Introduction to test automation in java and php
JUnit Testing Framework A Complete Guide.pdf
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit testing in Unity

More from Kiki Ahmadi (10)

PDF
Personal Finance in Indonesia - Market Research and Product
PPTX
Tentang Saya - Kiki Ahmadi
PDF
Kiki Ahmadi Resume 2014
PPTX
Festival Gerakan Indonesia Mengajar 2013
PPTX
Kelas Inspirasi 2012
PPTX
Mobile networks for Sistem Informasi ITS
PDF
My Curriculum Vitae
ODP
OSUM ITS Presentation
PPTX
PureZilla - Firefox addon for product information searching
PPTX
Why Java
Personal Finance in Indonesia - Market Research and Product
Tentang Saya - Kiki Ahmadi
Kiki Ahmadi Resume 2014
Festival Gerakan Indonesia Mengajar 2013
Kelas Inspirasi 2012
Mobile networks for Sistem Informasi ITS
My Curriculum Vitae
OSUM ITS Presentation
PureZilla - Firefox addon for product information searching
Why Java

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Approach and Philosophy of On baking technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
Chapter 3 Spatial Domain Image Processing.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
20250228 LYD VKU AI Blended-Learning.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
Approach and Philosophy of On baking technology
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation

Simple Unit Testing With Netbeans 6.1

  • 1. Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek
  • 2. What is Unit Testing Method of testing that verifies the individual units of the code is working properly (Wikipedia). Test the smallest unit in source code
  • 3. Why Unit Testing Verifies 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.
  • 4. Unit Testing in Java 2 most used testing framework in java Junit TestNG This time we used Junit because its embedded in netbeans 6.1.
  • 5. What is Junit Is a unit test framework in java Developed by Kent Beck and Erich Gamma Widely 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)
  • 6. Simple JUnit Create 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
  • 7. Junit in Netbeans 6.1 You don’t need to load the jar into netbeans project. By default the jar is embedded in test libarary folder And also netbeans has test class and test case code generation menu
  • 8. Lets Do The Code Lets 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.
  • 10. Create Unit Test Choose this menu in netbeans Tools > Create Junit Test Or 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.
  • 14. Unit Testing Assign 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
  • 16. Thank You Have a nice unit testing day folks!!