J-Unit Framework - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

J-Unit Framework

Description:

J-Unit Framework What is xUnit? An automated unit test framework Provides the Driver for unit(s) Provides automatic test runs Provides automatic result checks ... – PowerPoint PPT presentation

Number of Views:148
Avg rating:3.0/5.0
Slides: 15
Provided by: Robert2215
Category:

less

Transcript and Presenter's Notes

Title: J-Unit Framework


1
J-Unit Framework
2
What is xUnit?
  • An automated unit test framework
  • Provides the Driver for unit(s)
  • Provides automatic test runs
  • Provides automatic result checks
  • Available for multiple languages
  • cppUnit
  • sUnit
  • Junit

3
Junit Terms
  • Failure Expected
  • Error Unexpected (Exception)
  • TestCase Collection of method tests
  • Test Fixture Object Reuse for multiple tests
  • TestSuite Collection of Test Cases
  • TestRunner Interface
  • awt, swing,text

4
Essential Classes
  • junit.framework.TestCase
  • Allows running multiple tests
  • Does all counting and reporting of errors
  • junit.framework.Assert
  • A set of assert methods
  • Test fails if the assert condition does not hold
  • If a test fails it is counted and reported
  • junit.framework.TestSuite
  • A collection of tests
  • Uses Java introspection to find all the methods
    start with "test and have void parameters.
  • TestSuite's run method executes all the tests

5
Class diagram
6
Example, Complex Class
public class Complex int real_part int
imaginary_part public Complex(int r, int i)
real_partr imaginary_parti
public Complex() real_part0
imaginary_part0 public boolean
Equal(Complex c) boolean result false
if ((real_partc.get_r())
(imaginary_partc.get_i())) resulttrue
return result public Complex Add(Complex
c) Complex result new Complex(c.get_r()re
al_part,c.get_i()imaginary_part) return
result public int get_r() return
real_part public int get_i() return
imaginary_part
7
Using Junit (Create Fixture)
  • public class ComplexTest extends TestCase
  • Complex c1
  • Complex c2
  • protected void setUp()
  • c1 new Complex(7,3)
  • c2 new Complex(12,6)
  • protected void tearDown()

8
Using Junit (Add Test Cases)
  • public void testAdd()
  • Complex result c1.Add(new Complex(5,3))
  • assertEquals(result.get_r(),c2.get_r())
  • assertEquals(result.get_i(),c2.get_i())
  • public void testEqual()
  • assertTrue(!c2.Equal(c1))
  • assertTrue(c1.Equal(new Complex(7,3)))

assertNull, assertNotNull, assertSame
9
Using Junit (Make Suite)
  • public static Test suite()
  • TestSuite suite new TestSuite()
  • suite.addTest(new ComplexTest(testAdd))
  • suite.addTest(new ComplexTest(testEqual))
  • return suite

10
Using Junit (Batch Invoke and Constructor)
  • public static void main(String args)
  • junit.textui.TestRunner.run(suite())
  • public ComplexTest(String s)
  • super(s)

11
The Graphical UI
12
UI on Failure
13
What Junit does not do
  • Figure out your tests for you
  • Calculate any coverage criteria
  • Test GUIs
  • Except extensions
  • JFCUnit
  • Jemmy
  • Pounder
  • Abbot

14
Administrative
  • Download latest version from
  • www.junit.org
  • Setup classpath to junit.jar
  • Include appropriate ui in main
  • Import junit.framework.
Write a Comment
User Comments (0)
About PowerShow.com