WuKong - Framework for Integrated Test
-
Upload
summer-lu -
Category
Technology
-
view
135 -
download
0
Transcript of WuKong - Framework for Integrated Test
WuKong - Framework for Integrated Test
Yang Lu
Agenda
• Background• Why, What, How• Goals of Framework • Test Scene• Run Test• Demo• Questions
Background
• WuKong, also known as the Monkey King, is a main character in the Chinese classical novel Journey to the West.
• WuKong last release was Hestia.• Wukong, is a Framework for Integrated Test.
Why we do?
• We need to manage Test Case.
• We need to run Test Case.
• We need to write Test Case.– Web UI Test– Http Test– Web Service Test– RPC Test– Database Test– Mobile Test– ……
Manager
Runner
Test Case
What we do?• Test Web App
– Manage Test Case
• Test Runner– Run Test Case
• Integration Test-Framework– JunitX– TestNG
• Test Scenario-Plugin– Selenium– WebDriver– HtmlUnit– Web Service(CXF)– RPC– Rubidium– DB Unit
How we do? – Integration Test Framework
Plugin Http Plugin
Framework Junit4
Runner TestNGWuKong API WuKong Impl
Module Manager Report ……
Test Engine Web App Mobile App ……
Test CaseTestCase
1TestCase
2 ……
Service Plugin
Web Plugin DB Plugin Mobile
Plugin
Runner
Test Case
ProgressModuleTest RunnerJunit3 FrameworkJunit4 Framework
100%
Database Test PluginCXF Test PluginRPC Test PluginWeb UI Test PluginHttp Test PluginMobile Test PluginBusiness ModulesWeb App
How we do? - Maven Projects
100%100%
100%100%
100%100%
100%0%
25%25%
Example/Demo 100%
Goals of Framework
Dependency injection / Spring IOC Annotations Oriented Programming(AOP) Code-Reuse / Loose Coupling Simplify Code Good Scalability Well defined API Apply to Multi-Scenarios
Scene – How to Write Test Case?
How to define Test Project Structure? Spring Test Case Config Test Case DBase Test Case Web Service Test Case RPC Service Test Case Web UI Test Case(Page Driver) Web UI Test Case(Command Driver)
Scene – How to define Test Project Structure?
Test Resource files
(Test Config File)
Junit4 Test Case
Test Service API
Log
Scene – How to Write a Spring Test Case?APIpublic interface IHelloService {
/** * @param name * @return */ public String hello(String name);}
IMPLpublic class HelloServiceImpl implements IHelloService {
@Override public String hello(String name) { return name.toUpperCase(); }}
How to Inject a Spring Bean?
@AnnoSpringContext( locations= {"/applicationContext.xml"} )public class DemoSpringBaseTestCase extends SpringBaseTestCase {
@AnnoSpringBean(springContextKey="{helloService}")private IHelloService helloService;
@Testpublic void test() { assertEquals(helloService.hello("summer"), "SUMMER");}}
Spring Bean XML<?xml version="1.0" encoding="UTF-8"?><beans ……>
<bean id="helloService" class="com.dell.hestia.testcase.demo.spring.impl.HelloServiceImpl"> </bean> </beans>
4
2
3
1
Spring Content
Spring Bean
Spring Bean
Scene – How to Write a Config Test Case?Config in XML
<?xml version="1.0" encoding="ISO-8859-1" ?><config> <index>https://www.google.com.hk/</name1> <email>[email protected]</name3> <passwd>xxxxxx</name4> </config>
How to Inject a Config field?@AnnoConfigContext(paths="wukong-config.xml")public class WebUIWebDriverPageDriver3Test extends SpringTestCase implements IConfigTestCase {
@AnnoConfigField(key="index") private String index;
@AnnoConfigField(key="email") private String email;
@AnnoConfigField(key="passwd") private String passwd;
@Test public void testConfig() throws Exception {
assertEquals(index, "https://www.google.com.hk/"); assertEquals(email, "[email protected]"); assertEquals(passwd, "xxxxxx"); }
}
2
1
Tag Interface
Scene – How to Write a DBase Test Case?SQL and Service in XML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN“ "sql-map-2.dtd">
<sqlMap namespace="UserService"> <typeAlias alias="User" type="com.dell.wukong.testcase.demo.domain.User" /> <select id="queryUsers" resultClass="User"> SELECT u.* FROM user u </select></sqlMap>
How to Inject a DAO Service Bean?@AnnoSpringContext(locations={"classpath:spring-testcase-demo-dao-service.xml"})@AnnoDataSource( database = DataBase.MySQL, pool = ConnPool.DBCP )public class DBaseTestCase extends SpringTestCase implements IDBaseTestCase {
@AnnoSpringBean() private IUserService userService;
@Test public void test1() { assertEquals(userService.queryUsers().size(), 0); }}
2
1
Data Source Anno
Database type Conn Pool
Tag Interface
Spring Bean
Spring Bean
Spring Content
Scene – How to Write a CXF Test Case?
How to create a CXF-Web Service Bean?public class CXFTestCase extends SpringTestCase implements ICXFTestCase {
@AnnoServiceCXF() private IHelloService helloService;
@Test public void test1() { assertEquals(helloService.hello("summer"), "SUMMER"); }}
Tag Interface
CXF Service Anno
Web Service CXF Client API in XML<?xml version="1.0" encoding="UTF-8"?><beans …>
<bean id="helloService" class="com.dell.wukong.testcase.demo.service.impl.HelloServiceImpl"></bean> <jaxws:server id="helloService" serviceBean="#helloService" address="http://localhost:8080/wukong/ws/helloWebService"> </jaxws:server>
</beans>
CXF Service Bean
Scene – How to Write a RPC Test Case?
RPC Client API in XML<?xml version="1.0" encoding="UTF-8"?><beans …>
<dubbo:reference id="helloService"interface="com.dell.wukong.testcase.demo.service.api.IHelloService"url="dubbo://127.0.0.1:20880/com.dell.wukong.testcase.demo.service.api.IHelloService"/>
</beans>
How to Inject a RPC Service Bean?public class RPCTestCase extends SpringTestCase implements IRPCTestCase {
@AnnoServiceRPC() private IHelloService helloService;
@Test public void test1() { assertEquals(helloService.hello("summer"), "SUMMER"); }
}
2
1
Tag Interface
RPC Service Anno
RPC Service Bean
TestCase base on WebDriverTestCase base on HttpUnit
Scene – Write a Web UI Test Case By Page Driver
public class WebUIHtmlUnitPageDriverTest extends SpringTestCase implements IWebUIHttpUnitTestCase {
public static String index = "https://www.google.com.hk/";
@AnnoBrowser(browser=Browser.FIREFOX)
private IBrowser browser;
@Test
public void testLogin() throws Exception {
// indexPage
IPage indexPage = this.browser.getPage(index);
// loginPage
IPage loginPage = indexPage.onClick("gbi4s1");
loginPage.setHtmlInputValue("Email", "[email protected]");
loginPage.setHtmlInputValue(“Passwd”, "*");
// loginedPage
IPage loginedPage = loginPage.onClick("signIn");
// assertEquals
assertEquals(true, loginedPage.isElementTextContent("gbi4t", "Yang Lu"));
}
}
public class WebUIHtmlUnitPageDriverTest extends SpringTestCase implements IWebUIWebDriverTestCase {
public static String index = "https://www.google.com.hk/";
@ AnnoBrowser(browser=Browser.FIREFOX)
private IBrowser browser;
@Test
public void testLogin() throws Exception {
// indexPage
IPage indexPage = this.browser.getPage(index);
// loginPage
IPage loginPage = indexPage.onClick("gbi4s1");
loginPage.setHtmlInputValue("Email", "[email protected]");
loginPage.setHtmlInputValue("Passwd", "*");
// loginedPage
IPage loginedPage = loginPage.onClick("signIn");
// assertEquals
assertEquals(true, loginedPage.isElementTextContent("gbi4t", "Yang Lu"));
}
}
AnnoBrowser
AnnoBrowser
Program to an interface and Annotation, not an implementation
1
2
3
1
2
3
Command DriverPage Driver
Scene – How to Write a Web UI Test Case by Command Driver?
public class WebUIHtmlUnitPageDriverTest extends SpringTestCase implements IWebUIHttpUnitTestCase {
public static String index = "https://www.google.com.hk/";
@AnnoBrowser(browser=Browser.FIREFOX)
private IBrowser browser;
@Test
public void testLogin() throws Exception {
// indexPage
IPage indexPage = this.browser.getPage(index);
}
}
public class WebUIHtmlUnitPageDriverTest extends SpringTestCase implements IWebUIHttpUnitTestCase {
public static String index = "https://www.google.com.hk/";
@AnnoBrowser(browser=Browser.FIREFOX)
private IBrowser browser;
@Test
public void testLogin() throws Exception {
// indexPage
IPage indexPage = this.browser.getPage(index);
}
}
// loginedPage
IPage loginedPage = indexPage.execute( new LoginCommand() );
Command is a set of program logic can be reused
// loginPage
IPage loginPage = indexPage.onClick("gbi4s1");
loginPage.setHtmlInputValue("Email", "[email protected]");
loginPage.setHtmlInputValue(“Passwd”, "*");
// loginedPage
IPage loginedPage = loginPage.onClick("signIn");
// assertEquals
assertEquals(true, loginedPage.isElementTextContent("gbi4t", "Yang Lu"));
How to Run Test Case?
Eclipse IDE Maven WuKong Runner How to manage and use different release JAR of test project running at the same time?
How to Run Test Case? – Eclipse IDE
Local Debug
How to Run Test Case? – Maven
Integration Test
How to Run Test Case? – WuKong Runner
Test Classes
Test XML File
Test XML Element
Test XML
Text
Runner API
Run Test Programmatical
ly using Java
How to Run Test Case? - How to manage and use different release JAR of one project running at the same time?
TestRunner
TestCaseClassLoader is custom Class Loader, use to isolate Class
TestCaseClassLoader - 1
Test-demo-1.0.0.jar
TestRunnerTestCaseClassLoader - 2
Test-demo-2.0.0.jar
Demo - Web App : Login
Demo – Web App : How to Manage Test Case
Demo – Web App : How to watch Test Web-App JVM
Questions
Thank you