TPTP JUnit Å×½ºÆ®¿¡ Å×½ºÆ® ¸Þ¼Òµå ¸ÊÇÎ

Java Ŭ·¡½º·ÎºÎÅÍ TPTP JUnit Å×½ºÆ®´Â ÀÚµ¿À¸·Î À̸§ÀÌ 'test'·Î ½ÃÀÛÇÏ´Â ¸Þ¼Òµå¸¦ ½Äº°Çϰí À̵éÀ» Å×½ºÆ® ¸Þ¼Òµå¿¡ ¸ÊÇÎÇÕ´Ï´Ù. ¿¹¸¦ µé¾î, Ŭ·¡½º SimpleTestÀÇ ¼Ò½º´Â ´ÙÀ½°ú °°½À´Ï´Ù.

 

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());
	}
}

 

 

À̸§ÀÌ 'test'·Î ½ÃÀÛÇÏ´Â ¸Þ¼Òµå´Â testAdd, testDivideByZero ¹× testEqualsÀÔ´Ï´Ù. ÀÌ ¸Þ¼Òµå´Â °³¿ä ÅÇÀÇ Å×½ºÆ® ¸Þ¼Òµå ºÐÇÒâ¿¡ ³ª¿­µË´Ï´Ù.

 

 

»ç¿ëÀÚ°¡ Å×½ºÆ® ÆíÁý±â¸¦ »ç¿ëÇÏ¿© Å×½ºÆ® ¸Þ¼Òµå¸¦ Ãß°¡ÇÏ¸é »õ ¸Þ¼Òµå°¡ Äڵ忡 Ãß°¡µË´Ï´Ù.

¶ÇÇÑ TPTP¿¡¼­ JUnit Ŭ·¡½º¸¦ ½ÇÇàÇÒ ¼ö ÀÖ±â À§ÇÑ ¿ä±¸»çÇ×Àº ÀÌ Å¬·¡½º°¡ static "Test suite()" ¸Þ¼Òµå(À̰ÍÀº Ç¥ÁØ JUnit »ç·ÊÀÓ)¸¦ °¡Á®¾ß ÇÑ´Ù´Â Á¡ÀÔ´Ï´Ù. µ¿ÀÛ ¼±ÅöõÀ» ¼±ÅÃÇÏÁö ¾ÊÀ¸¸é ÀÌ suite() ¸Þ¼Òµå ¹× ÇØ´ç ÄÁÅÙÃ÷°¡ ÀÚµ¿À¸·Î »ý¼ºµÇ¸ç, »ç¿ëÀÚ°¡ Å×½ºÆ® ÆíÁý±â¸¦ »ç¿ëÇÏ¿© Å×½ºÆ®¸¦ ÀúÀåÇÏ¸é °»½ÅµË´Ï´Ù. ÀÌ ¼±ÅöõÀ» ¼±ÅÃÇÏ¸é »ç¿ëÀÚ°¡ ÀÌ suite() ¸Þ¼Òµå¸¦ ±¸ÇöÇØ¾ß ÇÕ´Ï´Ù.

Å×½ºÆ® ¸Þ¼Òµå ÆíÁý¿¡ ´ëÇÑ Á¤º¸´Â JUnit Å×½ºÆ® ÆíÁý±â ÁÖÁ¦¸¦ ÂüÁ¶ÇϽʽÿÀ.

°ü·Ã °³³ä
JUnit Å×½ºÆ® ÆíÁý±â