Skip to main content
Activity (Hands-On)Grades 9 - 12

Testing Software Programs with JUnit

A photograph shows four teens around a computer, looking at the monitor and working on a project.In this activity, students experience the test-driven development approach to software testing, a sub component of the software/systems design process.

JUnit is a testing method that is included with NetBeans (Java) installs or can be downloaded from the web and included in the Java build. In this activity, students design tests for a provided Java class before the class methods are constructed using a process called test-driven development. To create a design, the software/system design process, which is a specific case of the engineering design process, is followed. After students create a design, it is implemented and tested and if necessary, the design undergoes editing to make sure it functions by testing the Java class correctly. To conclude the activity, students write the methods in the Java class using their tests to debug the program.

This activity is a problem-based learning experience that is designed to give students practice with the design process. Testing computer software (in this case Java classes) is a critical step in the design process that is often overlooked by students. If software engineers do not properly test their software they may produce a poor product with unhappy users at best, or a program that does not function at worst. Both of these situations are unacceptable. Testing is critical to good software development. This activity specifically focuses on this testing. The testing of computer software is actually a mini design cycle inside of the larger design cycle. To properly test, students must analyze, implement, test and edit their products to ensure that they function correctly.

After this activity, students should be able to:

  • Discuss the requirements for the code to be written.
  • Create JUnit tests that check the requirements.
  • Write code that implements the requirements.
  • Run JUnit tests and verify that the code passes the tests.

More Like This