1 / 20

Test-Driven Design for Introductory OO Programming

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.

gilda
Download Presentation

Test-Driven Design for Introductory OO Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Special Interest Group on Computer Science Education 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

  2. Does Your Program Perform as Expected? • We never know until we test it. • But WHEN do you start planning your test, • BEFORE writing the program or • AFTERthe program has been written? • The professional programming community has realized that if we plan our test AFTERthe coding stage, we often tailor our tests to the code, not the original problem statement. • Thus, TDD has been developed to address this problem.

  3. Test-Driven Design • TDD has been shown to • increase the productivityof programming teams and • improve the qualityof the code. However, most of the introductory classes provide • NO definition of WHAT IS TEST and • NO help on HOW TO DESIGN YOUR TEST WHY??? TDD sounds GREAT!!!

  4. Why don’t educators introduce TDD into the classes? • As a beginner, there are so much to learn. • Syntax, grammar , inheritance, polymorphism…… • To introduce TDD means they have to learn extra stuffs like: • Whole new design concept which is more advanced than the traditional ones. • A new testing framework such as JUnit, which provides full functionalities for • Defining test cases and • Evaluating the test results.

  5. http://www.chemistryland.com/CHM151S/00-Intro/02-Succeed/Obstacles/StepsLeftOut.jpghttp://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 • By developing testing skills hand-in-hand with programming skills, the students can • Practice good programming style • Since they have to make their code test-ableand easy-to-test. • Understand the programming concepts they are learning. • Since they have to know what to test.

  8. Introduce test concept to novice programmer • We 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 assertEqualsmethod in JUnit framework, we can define our own assertEquals( checkExpecthere ) with easy-to-use functionality.

  10. Transition to the real world • The previous approach works for simple class with simple data structures. • However, when it comes to testing complex data structures like a Binary Search Tree (BST), we got to redesign our testing strategy. • Think about evaluating several testscomparing 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 • We can design a simple testing library to address the previous problem. • The key features of this simple testing library: • Automating the comparison of the values of arbitrary instances of all classes. • 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 • If students want to define the equality by themselves, they can implement the same method from the ISameinterface: • The “tester” will compare two objects in a class if it implements the ISame interface.

  18. Summary (1/2) • It’s all about standing in the student’s shoes. • When it comes to teaching the concept of testing, experienced programmers might just want to tell the rookies to use tools like JUnit. • However, it is a very BIG step for the rookies to cross basic OO knowledge to complex unit testing framework.

  19. Summary (2/2) • This paper provides a step-by-step approach to introduce the testing concept to students: • In the beginning, they know nothing about testing. • Then they know how to test their class in functional way. • 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. • For advanced purposes, the students can also define the equality comparison by themselves through ISame interface implementation. • Hopefully by following these works the students can transit smoothly to using professional tools like JUnit.

  20. Thank You!

More Related