Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Application Testing Guide
Previous Page Home Next Page

Mapping test methods to a TPTP JUnit test

From the Java class, TPTP JUnit Test automatically identifies methods whose names begin with 'test' and maps these onto Test Methods. For example, the source of the class SimpleTest is as follows:

package junit.samples;
import junit.framework.*;
/**
* Some simple tests.
*
*/
public class SimpleTest extends TestCase 
{
	protected int fValue1;
	protected int fValue2;

	protected void setUp() 
	{
	fValue1= 2;
	fValue2= 3;
	}

	public static Test suite() 
	{
	/*
	* the type safe way
	*
	TestSuite suite= new TestSuite();
	suite.addTest(new SimpleTest("add") 
	{
	protected void runTest() { testAdd(); }
	});

	suite.addTest(new SimpleTest("testDivideByZero") 
	{
	protected void runTest() { testDivideByZero(); }
	});

	return suite;
	*/
	
	/*
	* the dynamic way
	*/

	return new TestSuite(SimpleTest.class);
}


	public void testAdd() 
	{
		double result= fValue1 + fValue2;
		// forced failure result == 5
		assertTrue(result == 6);
	}

	public void testDivideByZero() 
	{
		int zero= 0;
		int result= 8/zero;
	}

	public void testEquals() 
	{
		assertEquals(12, 12);
		assertEquals(12L, 12L);
		assertEquals(new Long(12), new Long(12));
		assertEquals("Size", 12, 13);
		assertEquals("Capacity", 12.0, 11.99, 0.0);
	}


	public static void main (String[] args) 
	{
		junit.textui.TestRunner.run(suite());
	}
}

There are 3 methods whose names begin with 'test': testAdd, testDivideByZero, and testEquals. These methods are listed in the Test Methods pane of the Overview tab.

Note that, if the user adds a test method using the test editor, a new method will be added to the code.

Also, a requirement for being able to run a JUnit class in TPTP is that this class must have a static "Test suite()" method (which is a standard JUnit practice). When the behavior check box is unchecked, this suite() method and its content are automatically generated (and updated when the user saves the test using the test editor). When the check box is checked, the user has to implement this suite() method.

To learn about editing methods on the test, read the JUnit Test Editor topic.

Related concepts
JUnit Test Editor


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire