cs2110-sweng-2

cs2110-sweng-2 - CS 2110 Software Design Principles II Juan...

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

View Full Document Right Arrow Icon
CS 2110 Software Design Principles II 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 Last week: Refactoring Today : Test-Driven Development TDD + JUnit by Example
Background image of page 2
The Example A collection class SmallSet containing up to N objects (hence “small”) typical operations: we’ll implement add() , size() add adds item contains item in the set? size # items
Background image of page 3

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
Background image of page 4
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 org.junit.Test; import static org.junit.Assert.*; public class SmallSetTest { @Test public void testFoo () { SmallSet s = new SmallSet(); ... assertTrue (...); } @Test public void testBar() { ... } }
Background image of page 5

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 veriFes a certain “ feature
Background image of page 6
A First Test We pick a feature and test it: This doesn’t compile: size() is unde±ned 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()); } }
Background image of page 7

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

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

This note was uploaded on 02/01/2010 for the course CS 2110 at Cornell.

Page1 / 22

cs2110-sweng-2 - CS 2110 Software Design Principles II Juan...

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

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