Your SlideShare is downloading. ×
0
Unit Testing with JAVADinuka Malalanayake13-12-2011“Any Unit Test is better than none”
Objectives    Unit testing?    About JUnit    How to do the Unit testing with JAVA    Best Practices    Advantages  ...
Unit testing?    A unit test is a procedure used to verify that a    particular module of source code is working    prope...
About Junit    Junit is an open source unit testing    framework for JAVA.    Junit has plugin for Eclipse, NetBeans.......
Making the Environment    Download the eclipse    Configure JUnit or Testng framework
How to do the Unit testing with                  JAVA?    Pre Requirement     −   Source code     −   Test Framework     ...
Test Fixture in Junit    import org.junit.*;    @Test    @Before    @After    @BeforeClass    @AfterClass    @Ignor...
Test Fixture in Testng    import org.testng.*    @Test    @BeforeMethod    @AfterMethod    @BeforeClass    @AfterCla...
Way of working in Junit    @BeforeClass    −   @Before                    @Test    −   @After    −   @Before           ...
Way of working in Testng    @BeforeClass    −   @BeforeMethod                    @Test    −   @AfterMethod    −   @Befor...
Assertion    import junit.framework.Assert;    assertEquals    assertFalse    assertNotNull    assertNotSame    asse...
Steps for Unit testing    Create JAVA Project by using the Eclipse    Write the simple class                 public clas...
Class AccountType          Namefloat         minimumBalancefloat         balanceReturn type   Namevoid          setMinimum...
Best Practices    No conditional logic – Switch, if    No loops    Use appropriate method names    Informative asserti...
Advantages    Fast    Test Isolation    Environment Isolation – Use Mock Objects    Unit testing gives you a safety ne...
Disadvantages    Unnecessary Unit Tests can lead to    considerably high maintenance cost to your    overall project“Any ...
Similar ProductsProgramming Language                  Unit Testing ToolC#                                    NUnitJava – J...
Q&A“Any Unit Test is better than none”
THANK YOU“Any Unit Test is better than none”
Unit testing with java
Unit testing with java
Unit testing with java
Unit testing with java
Unit testing with java
Unit testing with java
Upcoming SlideShare
Loading in...5
×

Unit testing with java

1,019

Published on

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

No Downloads
Views
Total Views
1,019
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Unit testing with java"

  1. 1. Unit Testing with JAVADinuka Malalanayake13-12-2011“Any Unit Test is better than none”
  2. 2. Objectives Unit testing? About JUnit How to do the Unit testing with JAVA Best Practices Advantages Disadvantages Similar Products“Any Unit Test is better than none”
  3. 3. Unit testing? A unit test is a procedure used to verify that a particular module of source code is working properly Mouse, Keyboard, Monitor Company wants to achieve three related goals − Faster time-to-market“Any Unit Test is better than none” − Higher quality − More flexibility
  4. 4. About Junit Junit is an open source unit testing framework for JAVA. Junit has plugin for Eclipse, NetBeans.....etc. It serves the same purpose as NUnit does in the DotNet Technologies, and is one of many in the xUnit family“Any Unit Test is better than none”
  5. 5. Making the Environment Download the eclipse Configure JUnit or Testng framework
  6. 6. How to do the Unit testing with JAVA? Pre Requirement − Source code − Test Framework − Test Methods“Any Unit Test is better than none”
  7. 7. Test Fixture in Junit import org.junit.*; @Test @Before @After @BeforeClass @AfterClass @Ignore….etc.“Any Unit Test is better than none”
  8. 8. Test Fixture in Testng import org.testng.* @Test @BeforeMethod @AfterMethod @BeforeClass @AfterClass @Test (enabled=false)….etc.“Any Unit Test is better than none”
  9. 9. Way of working in Junit @BeforeClass − @Before  @Test − @After − @Before  @Test − @After @AfterClass
  10. 10. Way of working in Testng @BeforeClass − @BeforeMethod  @Test − @AfterMethod − @BeforeMethod  @Test − @AfterMethod @AfterClass
  11. 11. Assertion import junit.framework.Assert; assertEquals assertFalse assertNotNull assertNotSame assertNull fail…etc.“Any Unit Test is better than none”
  12. 12. Steps for Unit testing Create JAVA Project by using the Eclipse Write the simple class public class Account { } Define the attributes and methods Create an Unit testing class Write down unit test code according to the specification“Any Unit Test is better than none”
  13. 13. Class AccountType Namefloat minimumBalancefloat balanceReturn type Namevoid setMinimumBalanace(float minimumBalanace)float getMinimumBalanace()float deposit(float amount)float getBalance()void deposit(float amount)void withdraw(float amount)void calculateInterest(float interestRate)void reSetAccount()
  14. 14. Best Practices No conditional logic – Switch, if No loops Use appropriate method names Informative assertion message Separation per type“Any Unit Test is better than none”
  15. 15. Advantages Fast Test Isolation Environment Isolation – Use Mock Objects Unit testing gives you a safety net when programmers re-factor or add functionality Unit tests can be used as documentation for other programmers Development process becomes more flexible“Any Unit Test is better than none”
  16. 16. Disadvantages Unnecessary Unit Tests can lead to considerably high maintenance cost to your overall project“Any Unit Test is better than none”
  17. 17. Similar ProductsProgramming Language Unit Testing ToolC# NUnitJava – J2ME JMUnitC CUnitC++ CppUnitphp PHPUnitPython PyUnit / py.test“Any Unit Test is better than none”
  18. 18. Q&A“Any Unit Test is better than none”
  19. 19. THANK YOU“Any Unit Test is better than none”
  1. A particular slide catching your eye?

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

×