Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats an example of a simple JUnit test case?

Case JUnit simple Test
0
Posted

Whats an example of a simple JUnit test case?

0

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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123