5 Testing - CS 2110 Based on slides originally by Juan...

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

View Full Document Right Arrow Icon
CS 2110 Software Design Principles II n Principles II Based on slides originally by Juan Altmayer Pizzorno port25.com
Background image of page 1

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

View Full DocumentRight Arrow Icon
Overview ± From recitation sections: ² Starting with an idea ² Developing code by a process of refinement ± But implementing pieces of code and testing those pieces is central to every one of the software engineering styles we considered ± Today : Test-Driven Development ³ TDD + JUnit by Example ± We use JUnit testing to evaluate your homework assignments… : rocess of refinement of code and testing those y one of the software nsidered elopment e evaluate your homework
Background image of page 2
Tests can be great! “In my country of Kazakhstan testing is very nice! Make many tests please! at! try of Kazakhstan very nice! tests please!
Background image of page 3

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

View Full DocumentRight Arrow Icon
Testing can be great! ± Many people ² Write code without being sure it will work ² Press run and pray ² If it fails, they change something random ± This ² Never works ² And ruins your Friday evening social plans ± Test-Driven Development saves the day! reat! ng sure it will work omething random evening social plans ent saves the day!
Background image of page 4
The Example ± A collection class SmallSet ² containing up to N objects ² typical operations: ² we’ll implement add() add contains size allSet bjects (hence “small”) (), size() adds item item in the set? # items
Background image of page 5

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

View Full DocumentRight Arrow Icon
Test Driven Development ± We’ll go about in small iterations 1. add a test 2. run all tests and watch the new one fail 3. make a small change 4. run all tests and see them all succeed 5. refactor (as needed) ± We’ll use JUnit elopment all iterations ch the new one fail e them all succeed
Background image of page 6
JUnit ± What do JUnit tests look like? SmallSet.java package edu.cornell.cs.cs2110; public class SmallSet { ... } SmallSetTest.java package edu.cornell.cs.cs2110; import import static public class } look like? mallSetTest.java ackage edu.cornell.cs.cs2110; port org.junit.Test; port static org.junit.Assert.*; ublic class SmallSetTest { @Test public void testFoo () { SmallSet s = new SmallSet(); ... assertTrue (...); } @Test public void testBar() { ... }
Background image of page 7

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

View Full DocumentRight Arrow Icon
A List of Tests ± We start by thinking about how to test, not how to implement ² size=0 on empty set ² size=N after adding N distinct elements ² adding element already in set doesn’t change it ² throw exception if adding too many ² ... ± Each test verifies a certain “feature” about how to test, t N distinct elements ady in set doesn’t change it ding too many ertain “feature”
Background image of page 8
A First Test ± We pick a feature and test it: ± This doesn’t compile: ± But that’s all right: we’ve started designing the interface by using it SmallSet class SmallSet {} SmallSetTest class SmallSetTest { @Test public void testEmptySetSize SmallSet s = new SmallSet(); assertEquals(0, s.size()); } } test it: size() is undefined ’ve started designing the etSize() { );
Background image of page 9

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

View Full DocumentRight Arrow Icon
± A test can be defined ± Running the test yields a red bar indicating failure: ± If we add the size function and re test, it works! SmallSet
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/30/2011 for the course CS 2110 taught by Professor Francis during the Fall '07 term at Cornell University (Engineering School).

Page1 / 32

5 Testing - CS 2110 Based on slides originally by Juan...

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

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