На оффсайте пример типа Хеллоу Ворлд заставил только Есть класс | Код | package com.test;
import com.test.LocalClass1;
public class LocalClass3 extends LocalClass2 {
/** * @param args */ public LocalClass3(int iOne) throws Exception { super( iOne ); String sOne = "sone"; String sTwo = "stwo"; String sThree = "sthree"; String sFour = "sfour"; setSOne( sOne ); setSTwo( sTwo ); setSThee( sThree ); setSFour( sFour ); }
public synchronized String getSSix(int iTwo) throws Exception { return super.getSFive( iTwo ); }
public synchronized int getIFour(LocalClass1 lc, String sSeven) throws Exception { return super.getIThree( sSeven ); }
}
|
таким образом есть класс являющийся екстендедом другого класса. Есть общий шаблон для юнит теста | Код |
// TODO rename package. // I recommend that it be the same as the target class. // Because, if it isn't same, it can't invoke a package scope methods. package com.test;
// TODO import the classes which is the targets of a unit testing. import org.testng.Assert;
/** * TODO DOCUMENT ME! * <br/> This is the template of a test class for a plain objects like a value object.<br/> * <br/> See also:<br/> * <a href="http://testng.org/doc/documentation-main.html" target="_new">TestNG documentation</a><br/> * <a * href="http://www-128.ibm.com/developerworks/java/library/j-testng/index.html" target="_new"> TestNG makes Java unit testing a breeze</a><br/> * <a href="http://www-128.ibm.com/developerworks/java/library/j-cq08296/index.html" target="_new"> In pursuit of code quality: JUnit 4 vs. TestNG</a> * * @author <author>,<br/>Last changed by $Author$ * @testng.test */ // TODO rename this class. // I recommend "Test" prefix to be put on the testing target class name. public class TestPlainObject extends Assert { /** * Initializing this class.<br/> * This method is executed only once before all the methods is executed. * * @testng.before-class = "true" */ public void setUp() throws Exception { // TODO write the initializing codes for this class. }
/** * Cleanup this class.<br/> * This method is executed only once after all the methods is executed. * * @testng.after-class = "true" */ public void tearDown() throws Exception { // TODO write the cleanup codes for this class. }
/** * Pre-execute codes.<br/> * This method is executed every time before each method is executed. * * @testng.before-method = "true" */ public void beginTest() throws Exception { // TODO write the initializing codes for each method. }
/** * Post-execute codes.<br/> * This method is executed every time after each method is executed. * * @testng.after-method = "true" */ public void endTest() throws Exception { // TODO write the cleanup codes for each method. }
// ---- The following is the testing methods. ----
/** * TODO DOCUMENT ME!<br/> * This sample is simple codes for a normal case. * * @testng.test */ public void testCase01() throws Exception { // TODO write the testing codes. }
/** * TODO DOCUMENT ME!<br/> * This sample is simple codes for a abnormal case.<br/> * If the codes threw java.lang.IllegalArgumentException, TestNG accept this case. * * @testng.test * @testng.expected-exceptions value = "java.lang.IllegalArgumentException" */ public void testCase02() throws Exception { // TODO write the testing codes. }
/** * A data providor. * * @testng.data-provider name = "data1" */ public Object[][] createData() throws Exception { return new Object[][] { { 1st argument, 2nd argument } }; }
/** * TODO DOCUMENT ME!<br/> * This sample is to run with parameters.<br/> * Parameters are given by dataProvirer. * * @testng.test dataProvider = "data1" */ public void testCase03(final String key, final String key2) throws Exception { // TODO write the testing codes. }
/** * TODO DOCUMENT ME!<br/> * This sample is to run after other methods.<br/> * If testCase01 or testCase02 failed, TestNG don't execute this method. * * @testng.test dependsOnMethods = "testCase01, testCase02" */ public void testCase04() throws Exception { // TODO write the testing codes. } }
|
подскажите плз хоть как примерно этот юнит тест писать, или дайте плз ссылочки где более сложные примеры рассматриваются?
|