DOC PREVIEW
UMD CMSC 131 - Lecture 13: unit testing

This preview shows page 1-2 out of 7 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lecture 13 unit testing Last time 1 Method overloading 2 this Today 1 Unit testing and JUnit CMSC 131 Fall 2007 Jan Plane adapted from Bonnie Dorr The problem Problems need to be able to make sure all parts are tested need to know in testing exactly which part was not as expected need to be able to keep the tests for modifications made later Unit testing helps overcome this problems of making sure everything is tested Unit testing test each class and each part of the class unit individually Goal is to eliminate inconsistencies between the API and the actual working of the code CMSC 131 Fall 2007 Jan Plane adapted from Bonnie Dorr 1 Unit Testing Unit testing helps overcome this problems of making sure everything is tested in a structured way Unit testing test each unit individually micro level each method or specifically each interaction described in the API Goal is to eliminate errors within classes Needs for unit testing Method for defining tests inputs expected outputs Method for running tests Method for reporting results One possibility write a driver for each class Driver class contains main method main method creates objects in class to be tested calls methods prints outputs User checks outputs determines correctness Good easy no special tools needed Bad tedious relies on human inspection of outputs CMSC 131 Fall 2007 Jan Plane adapted from Bonnie Dorr Another approach JUnit 2 JUnit A unit testing tool for Java Includes capabilities for Test definition including output checking Test running execution Result reporting Seamless integration with Eclipse Note In this class we will use JUnit 3 8 1 So when given a choice select JUnit 3 CMSC 131 Fall 2007 Jan Plane adapted from Bonnie Dorr 3 Structure of a JUnit 3 8 1 Test Case JUnit library import junit framework TestCase Test case name Needed will see why later in semester public class FunnyIntegerSetTest01 extends TestCase public void testInsert FunnyIntegerSet set new FunnyIntegerSet set insert 3 assertTrue set null Tests public void testFindClosest FunnyIntegerSet set new FunnyIntegerSet set insert 3 set insert 6 assertEquals 6 set findClosest 5 Assertions result checkers CMSC 131 Fall 2007 Jan Plane adapted from Bonnie Dorr 4 A Test Case Is A Class assertion checkers assertTrue expression assertFalse expression If statement is false keep running test otherwise halt test report fail assertEquals expression1 expression2 If statement is true keep running test otherwise halt test report fail If expression1 expression2 equal keep running test otherwise halt test report fail If test terminates without failing it passes that test It continues with all susequent tests regardless of passing or failing the current test CMSC 131 Fall 2007 Jan Plane adapted from Bonnie Dorr 5 Hints on Testing Give names to tests that relate to class being tested Develop some tests before you code Helps you to clarify what you are supposed to be doing Gives you some ready made tests to run while you code Use tests to debug How many tests Statement coverage develop tests to make sure each statement in class is executed at least once including constructors Decision coverage develop tests to make each condition if statement in program both true and false You should at least reach statement coverage in your own testing CMSC 131 Fall 2007 Jan Plane adapted from Bonnie Dorr 6


View Full Document

UMD CMSC 131 - Lecture 13: unit testing

Documents in this Course
Set #3

Set #3

7 pages

Exam #1

Exam #1

6 pages

Exam #1

Exam #1

6 pages

Notes

Notes

124 pages

Notes

Notes

124 pages

Load more
Download Lecture 13: unit testing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 13: unit testing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 13: unit testing and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?