Adding software testing to programming assignments has many benefits, but many educators don't know where to start. This tutorial will show you how.
This tutorial provides a practical introduction to how one can incorporate software testing activities as a regular part of programming assignments, supported by live demonstrations, with a special focus on early introduction in CS1 and/or CS2 courses. It presents five different models for how one can incorporate testing into assignments, provides examples of each technique, and discusses the corresponding advantages and disadvantages. The focus is on unit testing, test-driven development, and incremental testing, all of which work well in a classroom environment. Examples will use Java, although participant discussion regarding support in other languages such as Python and C++ is welcome. Approaches to assessment--using testing to assess student code, assessing tests that students write, and automated grading--are all discussed. A live demonstration of automatic assignment grading based on student-written tests is included. Advice for writing "testable" assignments is given. Participant discussions are encouraged.
If you wish to get started with software testing in your assignments (for Java especially), the following materials will help you on your path:
What is Test-driven Development?: Read a brief overview of what TDD is.
What is JUnit?: A lightning overview of this testing framework.
Set up your IDE for using JUnit: Make sure you have an IDE installed on your computer with support for JUnit. We have instructions on how to do so for BlueJ, jGrasp, NetBeans, and Eclipse. If you prefer to use the command line, that's fine too. The examples in this tutorial use JUnit 3.x, since that is the choice employed by most educators (but JUnit 4.x works, too!).
Make sure you have set up your own environment for using JUnit if you want to try out some of the examples posted here on your own later.
Adding Testing to Assignments Discussion Forum: we have an on-line forum set up (use Facebook Connect to login, or create an account) on the Web-CAT web site for you to ask questions, discuss ideas, and share with each other; feel free to use it before, during, and after the tutorial.
JUnit Discussion Forum: there is also a similar forum specifically focused on JUnit questions and issues; feel free to use it as well.
Presentation: Adding Software Testing to Programming Assignments (PDF, 14 pp.)
The examples shown in the tutorial:
Example 0: DvrRecording: What does a JUnit test look like?
Example 1: Gradebook: Using tests as part of an assignment specification.
Example 2: Appointments: Using "acceptance tests" to check student work.
Example 3: Bricks: Assignments that focus on testing/debugging rather than code writing.
Example 4: HelloWorld: Testing main programs, stdi/o, etc.
Example 5: PushCounter: Testing Swing GUI applications using LIFT.
testing-in-assignments.zip: An Eclipse workspace containing all of these examples.
student.jar: JUnit
support library used by Web-CAT and many universities,
including student.TestCase
,
student.GUITestCase
, LIFT, and more.
Source code for student.jar and LIFT is open-source, available from the Web-CAT project on SourceForge.
JUnit.org has more information on how to use JUnit.
Documentation for the asserts in JUnit: http://www.junit.org/apidocs/org/junit/Assert.html
Testing GUI Programs is a Prezi presentation that gives a good introduction to LIFT and how it is used.
The LIFT website provides more details on LIFT, including links to two sigcse papers, downloads, examples, and discussion forums.