test-driven design for introductory oo programming

20
Test-Driven Design for Introductory OO Programming Viera K.Proulx College of Computer Science Northeastern University Boston, MA ACM SIGCSE’09, March 3–7, 2009, Chattanooga, Tennessee, USA. S pecial Interest Group on Computer Science Education

Upload: gilda

Post on 23-Feb-2016

60 views

Category:

Documents


1 download

DESCRIPTION

S pecial I nterest G roup on C omputer S cience E ducation. Test-Driven Design for Introductory OO Programming. ACM SIGCSE’09 , March 3–7, 2009, Chattanooga, Tennessee, USA. Viera K.Proulx College of Computer Science Northeastern University Boston, MA. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Test-Driven Design for Introductory OO Programming

Test-Driven Design for Introductory OO ProgrammingViera K.ProulxCollege of Computer ScienceNortheastern UniversityBoston, MA

ACM SIGCSE’09,

March 3–7, 2009,

Chattanooga,

Tennessee, USA.

Special Interest Group on Computer Science Education

Page 2: Test-Driven Design for Introductory OO Programming

2

Does Your Program Perform as Expected?

0We never know until we test it.0But WHEN do you start planning your test,

1. BEFORE writing the program or2. AFTER the program has been written?

0The professional programming community has realized that if we plan our test AFTER the coding stage, we often tailor our tests to the code, not the original problem statement.

0Thus, TDD has been developed to address this problem.

Page 3: Test-Driven Design for Introductory OO Programming

3

Test-Driven Design

0TDD has been shown to1. increase the productivity of programming teams and2. improve the quality of the code.

However, most of the introductory classes provide3. NO definition of WHAT IS TEST and4. NO help on HOW TO DESIGN YOUR TEST

WHY??? TDD sounds

GREAT!!!

Page 4: Test-Driven Design for Introductory OO Programming

4

Why don’t educators introduce TDD into the classes?

0As a beginner, there are so much to learn.0 Syntax, grammar , inheritance, polymorphism……

0To introduce TDD means they have to learn extra stuffs like:0 Whole new design concept which is more advanced

than the traditional ones.0 A new testing framework such as JUnit, which provides

full functionalities for0Defining test cases and0Evaluating the test results.

Page 5: Test-Driven Design for Introductory OO Programming

5http://www.chemistryland.com/CHM151S/00-Intro/02-Succeed/Obstacles/StepsLeftOut.jpg

Page 6: Test-Driven Design for Introductory OO Programming

6

However, we can still try introduce TDD in

simple way

Page 7: Test-Driven Design for Introductory OO Programming

7

The benefits of developing testing skills

0By developing testing skills hand-in-hand with programming skills, the students can 0Practice good programming style0Since they have to make their code test-able and

easy-to-test.0Understand the programming concepts they are

learning.0Since they have to know what to test.

Page 8: Test-Driven Design for Introductory OO Programming

8

Introduce test concept to novice programmer

0We can start from this simple example:

We want to test if this method works as we expected it to be.

Page 9: Test-Driven Design for Introductory OO Programming

9

Test design in the functional style

For the beginners, forget about the complex assertEquals method in JUnit framework, we can

define our own assertEquals ( checkExpect here )

with easy-to-use functionality.

Page 10: Test-Driven Design for Introductory OO Programming

10

Transition to the real world

0The previous approach works for simple class with simple data structures.

0However, when it comes to testing complex data structures like a Binary Search Tree (BST), we got to redesign our testing strategy.0 Think about evaluating several tests comparing 2 BSTs

with 6 nodes, 7 leaves, and where the data in each node consists of 3 fields……

Page 11: Test-Driven Design for Introductory OO Programming

11

Time to bring in the testing library

0We can design a simple testing library to address the previous problem.

0The key features of this simple testing library:1. Automating the comparison of the values of arbitrary

instances of all classes.2. Produce the test results with display of the actual

and expected values of each failed test.

Page 12: Test-Driven Design for Introductory OO Programming

12

Let’s take a look at an example of the simple testing

library ( called “tester” )

Page 13: Test-Driven Design for Introductory OO Programming

13

This is the class we want to test

Actually, what we really want to test is this functionality.

Page 14: Test-Driven Design for Introductory OO Programming

14

This is the testing class

The testing library package

Each test case is specified as an invocation of a method in the Tester class.

Several test cases are typically grouped together in a method with a name that starts with “test”.

Page 15: Test-Driven Design for Introductory OO Programming

15

The testing report

Class fields and the corresponding values

Number of tests performed and number of failed tests

For each failed test, display the actual and expected values

Page 16: Test-Driven Design for Introductory OO Programming

16

Special tests provided by “tester”

Page 17: Test-Driven Design for Introductory OO Programming

17

User defined equality

0 If students want to define the equality by themselves, they can implement the same method from the ISame interface:

0The “tester” will compare two objects in a class if it implements the ISame interface.

Page 18: Test-Driven Design for Introductory OO Programming

18

Summary (1/2)

0 It’s all about standing in the student’s shoes.0 When it comes to teaching

the concept of testing, experienced programmers might just want to tell the rookies to use tools like JUnit.

0 However, it is a very BIG step for the rookies to cross basic OO knowledge to complex unit testing framework.

Page 19: Test-Driven Design for Introductory OO Programming

19

Summary (2/2)

0 This paper provides a step-by-step approach to introduce the testing concept to students:1. In the beginning, they know nothing about testing.2. Then they know how to test their class in functional way.3. For complex test cases, the author suggests the instructor to

provide an easy-and-simple-to-use testing library, teaching the students the concept of testing automation.

4. For advanced purposes, the students can also define the equality comparison by themselves through ISame interface implementation.

0 Hopefully by following these works the students can transit smoothly to using professional tools like JUnit.

Page 20: Test-Driven Design for Introductory OO Programming

20

Thank You!