Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit Testing with JUnit Dan Fleck Fall 2007 (For both CS211 and 421… two birds… one lecture! :-)

Similar presentations


Presentation on theme: "Unit Testing with JUnit Dan Fleck Fall 2007 (For both CS211 and 421… two birds… one lecture! :-)"— Presentation transcript:

1 Unit Testing with JUnit Dan Fleck Fall 2007 (For both CS211 and 421… two birds… one lecture! :-)

2 What is Unit Testing? ZA procedure to validate individual units of Source Code ZExample: A procedure, method or class ZValidating each individual piece reduces errors when integrating the pieces together later

3 Automated Unit Tests with JUnit ZJunit is a unit testing framework for Java ZAllows you to write unit tests in Java using a simple interface ZAutomated testing enables running and rerunning tests very easily and quickly

4 An example unit test public void testCellChangePropagates() { Spreadsheet sheet = new Spreadsheet(); sheet.put("A1", "5"); sheet.put("A2", "=A1"); sheet.put("A1", "10"); assertEquals("10",sheet.get("A2")); }

5 Junit with Netbeans 1.New File 2.Choose file type: Junit 3.Choose Test for Existing Class 4.Junit test with all stubs created for that class 5.Fill in the individual tests 6.Run Tests (Netbeans options)

6 Coverage Analysis ZDetermining which lines of code your tests have exercised and which they have not ZAllows you to detect if your unit tests (or system tests) are adequately covering all possibilities or not ZThis is just one way to test

7 Coverage Analysis with Netbeans ZInstall Unit Test Code Coverage Viewer module ZWrite a Unit Test ZRun test and view highlighted code

8 A simple test to dynamically cover your code: public void testMain() { SuDoku sFrame = new SuDoku(); while (sFrame.isDisplayable()) { try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } Assert.assertEquals(true,true); }

9 Summary ZUnit tests can help test the details of your program ZAutomated unit tests provide constant visibility and easy retesting ZTest coverage supplies valuable information when running both unit tests and system tests


Download ppt "Unit Testing with JUnit Dan Fleck Fall 2007 (For both CS211 and 421… two birds… one lecture! :-)"

Similar presentations


Ads by Google