Lecture11

Lecture11 - Testing The process of running a program on a...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Testing The process of running a program on a set of test cases and comparing the actual results with expected results. public class SimpleDotCom { int[] locationCells; int numOfHits = 0; public String checkYourself(String stringGuess) { int guess = Integer.parseInt(stringGuess); String result = "miss"; for (int cell : locationCells) { if (guess == cell) { result = "hit"; numOfHits++; break; } // end if } // end for if (numOfHits == locationCells.length){ result = "kill"; } System.out.println(result); return result; } } public class SimpleDotComTestDrive { public static void main (String[] args) { SimpleDotCom dot = new SimpleDotCom(); int[] locations = {2,3,4}; dot.setLocationCells (locations) ; String userGuess = "2"; String result = dot.checkYourself(userGuess); String testResult = “failed”; if (result.equal(“hit”)) { TestResult = “passed”; } System.out.println(testResult); } } What we should test: 1. Instantiate a SimpleDotCom object. 2. Assign it a location (an array of 3 ints, like {2,3,4}). 3. Create a String to represent a user guess ("2", "0", etc.). 4. Invoke the checkYourself() method passing it the fake user guess. 5. Print out the result to see if it's correct ("passed" or "failed").
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Types of Testing Unit testing : a test of a single class A test case tests the response of a single method to a particular set of inputs Integration testing : a test of how well classes work together. Test the combination of two or more classes. Unit testing should always precede integration testing
Background image of page 2
3 Tutorial of Junit A simple framework for testing Java programs Tool of Unit test Example: Counter class The constructor will create a counter and set it to zero
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/12/2010 for the course COE 318 taught by Professor Ken during the Spring '08 term at Ryerson.

Page1 / 18

Lecture11 - Testing The process of running a program on a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online