Whats an example of a simple JUnit test case?
Location: http://www.jguru.com/faq/view.jsp?EID=25537 Created: Mar 17, 2000 Modified: 2000-09-12 19:32:44.978 Author: Tom Copeland (http://www.jguru.com/guru/viewbio.jsp?EID=1396) Say you’ve got a little method, getName(String path) that parses a file name from a file path. You can write a JUnit test class to feed it a path and ensure that the results are what you expected. public class ThingTester extends TestCase { public ThingTester (String name) { super (name); } public static void main(String[] args) { TestRunner.runAndWait(new TestSuite(ThingTester.class)); } public void testGetName() throws Exception { String fileSpec = new String(“c:\\xxx\\yyy\\zzz.txt”); assertEquals(“zzz.txt”, getName(fileSpec)); } } Now compile and run ThingTester. A little dot will appear if all is well; otherwise, an assertion failure and a stack trace will let you know where the problem is. If there are no problems, you can add more test cases with long paths, files with spaces in the name, etc., etc., un