test-driven design for introductory oo programming

Post on 23-Feb-2016

62 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

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

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

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.

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!!!

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.

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

6

However, we can still try introduce TDD in

simple way

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.

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.

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.

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……

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.

12

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

library ( called “tester” )

13

This is the class we want to test

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

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”.

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

16

Special tests provided by “tester”

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.

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.

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.

20

Thank You!

top related