TestNG Example"

From Documentation
(2 intermediate revisions by one other user not shown)
Line 2: Line 2:
  
  
This test case perform exactly the same test as the JUnit one. It is just written in TestNG's annotation, please refer to [http://testng.org/doc/index.html].
+
This test case performs exactly the same as the JUnit one except that it is written in TestNG's annotation, please refer to [http://testng.org/doc/index.html].
  
 
To run a TestNG test case, please refer to [http://testng.org/doc/documentation-main.html#running-testng Run TestNG].
 
To run a TestNG test case, please refer to [http://testng.org/doc/documentation-main.html#running-testng Run TestNG].
Line 40: Line 40:
 
</source>
 
</source>
  
* It has little difference with JUnit test case. You only need to change <tt> @After </tt> to <tt> @AfterMethod </tt> and <tt> import org.junit.* </tt> to <tt> import  org.testng.* </tt>.
+
* It has little difference to the JUnit test case. You only need to change <tt> @After </tt> to <tt> @AfterMethod </tt> and <tt> import org.junit.* </tt> to <tt> import  org.testng.* </tt>.
 
 
  
  
 +
{{ZATSEssentialsPageHeader}}
 
{{ZATSEssentialsPageFooter}}
 
{{ZATSEssentialsPageFooter}}

Revision as of 08:05, 21 June 2012



This test case performs exactly the same as the JUnit one except that it is written in TestNG's annotation, please refer to [1].

To run a TestNG test case, please refer to Run TestNG.


public class HelloTestNg {
	@BeforeClass
	public static void init() {
		Zats.init("./src/main/webapp");
	}

	@AfterClass
	public static void end() {
		Zats.end();
	}

	@AfterMethod
	public void after() {
		Zats.cleanup();
	}

	@Test
	public void test() {
		DesktopAgent desktop = Zats.newClient().connect("/hello.zul");

		ComponentAgent button = desktop.query("button");
		ComponentAgent label = desktop.query("label");
		
		//button.as(ClickAgent.class).click();
		button.click();
		Assert.assertEquals("Hello Mimic", label.as(Label.class).getValue());
	}
}
  • It has little difference to the JUnit test case. You only need to change @After to @AfterMethod and import org.junit.* to import org.testng.* .




Last Update : 2012/06/21

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.