junit-test-example
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
junit-test-example [2008/10/12 07:22] – jtkorb | junit-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. | ||
+ | * For command-line testing in the UNIX/Linux environment, | ||
+ | |||
====== Testing Your Project ====== | ====== Testing Your Project ====== | ||
//Test early, test often.// | //Test early, test often.// | ||
- | |||
- | As the project specifications point out, it is difficult to redirect standard input from within DrJava, forcing you to constantly flip back and forth between the IDE and the command line. Here's an approach that gets around this problem and also makes it easy for you to add additional tests as you develop your code. | ||
Use a [[http:// | Use a [[http:// | ||
Line 9: | Line 11: | ||
Both DrJava and Eclipse include JUnit support. | Both DrJava and Eclipse include JUnit support. | ||
- | To use JUnit to test your main method, you need to make a minor structural change. | + | |
+ | ====== 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. | ||
+ | |||
+ | To use JUnit to test your main method | ||
Your '' | Your '' | ||
Line 58: | Line 65: | ||
+ | ====== Command-Line JUnit Testing in UNIX ====== | ||
- | ====== Command Line Testing on UNIX ====== | + | Here is a minimalist way to do command-line JUnit testing in the UNIX/Linux environment. |
- | + | ||
- | Here is a minimalist way to do command line JUnit testing in the UNIX/Linux environment. | + | |
- Download the latest JUnit jar file from http:// | - Download the latest JUnit jar file from http:// | ||
- Put this jar file into the same directory as your test class and other project files. | - Put this jar file into the same directory as your test class and other project files. | ||
- | - Compile your test class, adding junit-4.5.jar to your class path. A simple way is with the '' | + | - Compile your test class, adding junit-4.5.jar to your classpath (either using the '' |
- Run your test class using the text-based JUnit runner, '' | - Run your test class using the text-based JUnit runner, '' | ||
- | Here is a simple | + | Here is a script, named '' |
#!/bin/sh | #!/bin/sh | ||
- | | + | |
- | java -cp .: | + | javac $1.java |
+ | java junit.textui.TestRunner $1 | ||
If your test class is named, say, '' | If your test class is named, say, '' | ||
- | $ tester SpellCheckerTester | + | $ ./tester SpellCheckerTester |
+ | For more general-purpose use, put the '' |
junit-test-example.txt · Last modified: 2008/10/25 08:58 by jtkorb