wukong - framework for integrated test
TRANSCRIPT
![Page 1: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/1.jpg)
WuKong - Framework for Integrated Test
Yang Lu
![Page 2: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/2.jpg)
Agenda
• Background• Why, What, How• Goals of Framework • Test Scene• Run Test• Demo• Questions
![Page 3: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/3.jpg)
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.
![Page 4: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/4.jpg)
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
![Page 5: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/5.jpg)
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
![Page 6: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/6.jpg)
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
![Page 7: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/7.jpg)
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%
![Page 8: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/8.jpg)
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
![Page 9: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/9.jpg)
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)
![Page 10: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/10.jpg)
Scene – How to define Test Project Structure?
Test Resource files
(Test Config File)
Junit4 Test Case
Test Service API
Log
![Page 11: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/11.jpg)
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
![Page 12: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/12.jpg)
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
![Page 13: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/13.jpg)
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
![Page 14: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/14.jpg)
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
![Page 15: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/15.jpg)
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
![Page 16: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/16.jpg)
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
![Page 17: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/17.jpg)
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"));
![Page 18: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/18.jpg)
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?
![Page 19: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/19.jpg)
How to Run Test Case? – Eclipse IDE
Local Debug
![Page 20: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/20.jpg)
How to Run Test Case? – Maven
Integration Test
![Page 21: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/21.jpg)
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
![Page 22: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/22.jpg)
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
![Page 23: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/23.jpg)
Demo - Web App : Login
![Page 24: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/24.jpg)
Demo – Web App : How to Manage Test Case
![Page 25: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/25.jpg)
Demo – Web App : How to watch Test Web-App JVM
![Page 26: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/26.jpg)
Questions
![Page 27: WuKong - Framework for Integrated Test](https://reader036.vdocuments.mx/reader036/viewer/2022062319/554a19cab4c9055c598b5313/html5/thumbnails/27.jpg)
Thank you