User Tools

Site Tools


junit-test-example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
junit-test-example [2008/10/12 08:19] jtkorbjunit-test-example [2008/10/25 08:58] (current) jtkorb
Line 1: Line 1:
 +**Updates**
 +  * Project 3 neither reads from standard input nor writes gradeable text to standard output, so the mechanism below to redirect these two streams to files is not necessary for this project.  Instead, your JUnit test routines can just call ''main'' directly with different versions of the ''String[] args'' array to indicate different input test files.
 +  * For command-line testing in the UNIX/Linux environment, see the new section [[#Command-Line JUnit Testing in UNIX|below]].
 +
 ====== Testing Your Project ====== ====== Testing Your Project ======
  
 //Test early, test often.// //Test early, test often.//
- 
-**Updates** 
-  * Project 3 neither reads from standard input nor writes gradeable text to standard output, so the mechanism below to redirect these two streams to files is not necessary for this project.  Instead, your JUnit test routines can just call ''main'' directly with different versions of the ''String'' ''args'' array. 
-  * For command-line testing in the UNIX/Linux environment, see the new section [[#Command-Line JUnit Testing in UNIX|below]]. 
  
 Use a [[http://www.junit.org|JUnit]] test case.  JUnit is a Java package that facilitates "unit testing": creation, execution, and evaluation of repeatable tests on your code.  It is designed to support incremental testing ([[http://en.wikipedia.org/wiki/Test-driven_development|test-driven development]]), but can also be used in a variety of ways including "whole program" testing.   Use a [[http://www.junit.org|JUnit]] test case.  JUnit is a Java package that facilitates "unit testing": creation, execution, and evaluation of repeatable tests on your code.  It is designed to support incremental testing ([[http://en.wikipedia.org/wiki/Test-driven_development|test-driven development]]), but can also be used in a variety of ways including "whole program" testing.  
Line 11: Line 11:
 Both DrJava and Eclipse include JUnit support.  ([[http://www.drjava.org/userdocs/junit.html|Chapter 7]] in the DrJava help documentation has details.) Both DrJava and Eclipse include JUnit support.  ([[http://www.drjava.org/userdocs/junit.html|Chapter 7]] in the DrJava help documentation has details.)
  
-===== Testing Programs that Read from Standard In and Write to Standard Out =====+ 
 +====== Testing Programs that Read from Standard In and Write to Standard Out ======
  
 For projects that take input from the command line (or redirected from a file) and produce gradable results to standard out, automated testing requires that these streams be redirected in the JUnit test class.  This section explains how to do that. For projects that take input from the command line (or redirected from a file) and produce gradable results to standard out, automated testing requires that these streams be redirected in the JUnit test class.  This section explains how to do that.
Line 62: Line 63:
     import java.io.PrintStream;     import java.io.PrintStream;
     import java.util.Scanner;     import java.util.Scanner;
 +
  
 ====== Command-Line JUnit Testing in UNIX ====== ====== Command-Line JUnit Testing in UNIX ======
Line 72: Line 74:
   - Run your test class using the text-based JUnit runner, ''junit.textui.TestRunner''.   - Run your test class using the text-based JUnit runner, ''junit.textui.TestRunner''.
  
-Here is a script, named ''tester'', that compiles and runs a test class given as the command line argument.+Here is a script, named ''javat'', that compiles and runs a test class given as the command line argument.
  
   #!/bin/sh   #!/bin/sh
Line 83: Line 85:
   $ ./tester SpellCheckerTester   $ ./tester SpellCheckerTester
  
-For more general-purpose use, put the ''jar'' file in your ''~/lib'' directory, add the correct ''CLASSPATH'' variable to your startup file (e.g., to ''~/.bashrc''), and the ''tester'' script to your personal ''~/bin'' directory (adding that directory to your ''PATH'', if necessary).+For more general-purpose use, put the ''jar'' file in your ''~/lib'' directory, add the correct ''CLASSPATH'' variable to your startup file (e.g., to ''~/.bashrc''or edit it into the tester script, and move the ''tester'' script to your personal ''~/bin'' directory (adding that directory to your ''PATH'', if necessary).
junit-test-example.1223824785.txt.gz · Last modified: 2008/10/12 08:19 by jtkorb