JUnit and JFCUnit Frameworks - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

JUnit and JFCUnit Frameworks

Description:

Test Fixture: Object Reuse for multiple tests. TestSuite: ... Jemmy. Pounder. Abbot. Administrative. Download latest version (3.8.1) from: www.junit.org ... – PowerPoint PPT presentation

Number of Views:134
Avg rating:3.0/5.0
Slides: 18
Provided by: Robert9
Category:

less

Transcript and Presenter's Notes

Title: JUnit and JFCUnit Frameworks


1
J-Unit and JFCUnit Frameworks
  • CS2335
  • Spring 2005

2
Agenda
  • JUnit
  • Demo
  • JFCUnit
  • Demo

3
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

4
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

5
Example, Complex Class
public class Complex int real int
imaginary public Complex(int r, int i)
realr imaginaryi public Complex()
real0 imaginary0 public
boolean equals(Complex c) boolean result
false if ((realc.real)
(imaginaryc.imaginary)) resulttrue
return result public Complex add(Complex
c) Complex result new Complex(c.real()rea
l,c.imaginaryimaginary) return result
public int getReal() return real public
int getImaginary() return imaginary
6
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()

7
Using Junit (Add Test Cases)
  • public void testAdd()
  • Complex result c1.add(new Complex(5,3))
  • assertEquals(result.getReal(),c2.getReal())
  • assertEquals(result.getImaginary(),
  • c2.get_Imaginary())
  • public void testEqual()
  • assertFalse(c2.equals(c1))
  • assertTrue(c1.equals(new Complex(7,3)))

assertNull, assertNotNull, assertSame
8
Using Junit (Make Suite)
  • import junit.framework.TestCase
  • import junit.framework.Test
  • import junit.framework.TestSuite
  • import junit.textui.TestRunner
  • public static Test suite()
  • TestSuite suite new TestSuite()
  • suite.addTest(new ComplexTest(testAdd))
  • suite.addTest(new ComplexTest(testEqual))
  • return suite

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

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

13
Administrative
  • Download latest version (3.8.1) from
  • www.junit.org
  • Setup classpath to junit.jar
  • Include appropriate ui in main
  • Import junit.framework. classes
  • Already in class resources
  • CS2335/java/junit

14
JFCUnit
  • Unit test extension to JUnit for Swing (JFC)
    based UI.
  • Derive classes from JFCTestCase vs. TestCase
  • Can obtain handles to GUI resources
  • Can send events to GUI resources
  • Takes over AWT thread with JFCTestHelper class

15
First make base class
public class MyAppTest extends JFCTestCase
private JFCTestHelper helper private MyApp
public MyAppTest(String s) super(s)
public void setUp() helpernew
JFCTestHelper() MyAppnew MyApp(JFC
Test) public static void main(String
args) TestRunner.run(MyAppTest.class)
16
Use helper class to manipulate
Finding stuff JButton exitButton ( JButton )
TestHelper.findNamedComponent(
"ExitButton", loginScreen, 0 )
assertNotNull( "Could not find the Exit button",
exitButton )
17
Next Time
  • More on Teams..
  • Problem Team Members
  • MBTI and effect on Development teams
Write a Comment
User Comments (0)
About PowerShow.com