cs2110-sweng-2-6up - Overview Last week: CS 2110 Software...

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

View Full Document Right Arrow Icon
CS 2110 Software Design Principles II Juan Altmayer Pizzorno port25.com Overview Last week: Refactoring Today : Test-Driven Development TDD + JUnit by Example 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 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 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() { ... } } 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 1

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

View Full DocumentRight Arrow Icon
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 {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

cs2110-sweng-2-6up - Overview Last week: CS 2110 Software...

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

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