Customize Test Environment"
From Documentation
(Created page with "{{ZATSEssentialsPageHeader}} When we use <tt> Zats </tt> to initialize the test case environment, it will '''load built-in web.xml and zk.xml '''. <source lang="java"> @Befo...") |
m (correct highlight (via JWB)) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
− | + | In a test case, we usually use <code> Zats </code> to initialize the test case environment, it will load '''Mimic built-in web.xml''' and '''zk.xml '''. | |
<source lang="java"> | <source lang="java"> | ||
Line 18: | Line 18: | ||
@Test | @Test | ||
public void test(){ | public void test(){ | ||
− | DesktopAgent desktop = Zats.newClient().connect("/ | + | DesktopAgent desktop = Zats.newClient().connect("/index.zul"); |
//... | //... | ||
Line 25: | Line 25: | ||
</source> | </source> | ||
− | + | == 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. | |
− | <source lang="java" | + | First, create your own <code> ZatsEnvironment</code> by '''<code> new DefaultZatsEnvironment("./src/test/env1/WEB-INF") </code>''' 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" highlight="7,8,19"> | ||
public class EnvironmentTest{ | public class EnvironmentTest{ | ||
Line 45: | Line 47: | ||
env.destroy(); | env.destroy(); | ||
} | } | ||
+ | |||
@Test | @Test | ||
public void testCustomConfig() { | public void testCustomConfig() { | ||
Client client = env.newClient(); | Client client = env.newClient(); | ||
− | DesktopAgent desktop = client.connect(" | + | DesktopAgent desktop = client.connect("/custom-config.zul"); |
//... | //... | ||
} | } | ||
} | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | == Custom Context Path == | ||
+ | |||
+ | Beside WEB-INF's path, you can also specify your '''web application context root path''' by passing 2nd parameter to <code> DefaultZatsEnvironment </code>'s constructor. | ||
+ | |||
+ | <source lang="java" highlight="7"> | ||
+ | |||
+ | 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"); | ||
+ | } | ||
+ | } | ||
</source> | </source> | ||
Line 59: | Line 81: | ||
+ | {{ZATSEssentialsPageHeader}} | ||
{{ZATSEssentialsPageFooter}} | {{ZATSEssentialsPageFooter}} |
Latest revision as of 02:54, 18 January 2022
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");
}
}