Customize Test Environment"

From Documentation
Line 31: Line 31:
 
First, create your own <tt> ZatsEnvironment</tt> by '''<tt> new DefaultZatsEnvironment("./src/test/env1/WEB-INF") </tt>''' with your "WEB-INF" path as the parameter. Then, use it to '''create a client ''' to connect to ZUL. The rest are the same as you do under default configuration.
 
First, create your own <tt> ZatsEnvironment</tt> by '''<tt> new DefaultZatsEnvironment("./src/test/env1/WEB-INF") </tt>''' with your "WEB-INF" path as the parameter. Then, use it to '''create a client ''' to connect to ZUL. The rest are the same as you do under default configuration.
  
<source lang="java" high="7,19">
+
<source lang="java" high="7,8,19">
  
 
public class EnvironmentTest{
 
public class EnvironmentTest{

Revision as of 06:37, 1 November 2012

Customize Test Environment




In a test case, we usually use Zats to initialize the test case environment, it will load Mimic built-in web.xml and zk.xml .

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

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

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

	}

Custom WEB-INF Path

However, most projects have their custom configuration in web.xml or need another one for testing purpose. Mimic provides a way to load custom web descriptor by specifying your WEB-INF folder.

First, create your own ZatsEnvironment by new DefaultZatsEnvironment("./src/test/env1/WEB-INF") with your "WEB-INF" path as the parameter. Then, use it to create a client to connect to ZUL. The rest are the same as you do under default configuration.

public class EnvironmentTest{

	static ZatsEnvironment env; 

	@BeforeClass
	public static void init(){
		env = new DefaultZatsEnvironment("./src/test/env1/WEB-INF");
		env.init("./src/main/webapp"); 
	}

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

	@Test
	public void testCustomConfig() {

		Client client = env.newClient();
		DesktopAgent desktop = client.connect("/custom-config.zul");
		//...
	}
}

Custom Context Path

Beside WEB-INF's path, you can also specify your web application context root path by passing 2nd parameter to DefaultZatsEnvironment 's constructor.

public class EnvironmentTest{

	static ZatsEnvironment env; 

	@BeforeClass
	public static void init(){
		env = new DefaultZatsEnvironment("./src/test/env1/WEB-INF", "/myapp");
		env.init("./src/main/webapp"); 
	}
}



Customize Test Environment




Last Update : 2012/11/01

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