WuKong - Framework for Integrated Test

515 views

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
515
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

WuKong - Framework for Integrated Test

  1. 1. WuKong - Framework for Integrated Test Yang Lu
  2. 2. Agenda • Background • Why, What, How • Goals of Framework • Test Scene • Run Test • Demo • Questions
  3. 3. 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.
  4. 4. 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
  5. 5. 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
  6. 6. 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 Case TestCase1 TestCase2 …… Service Plugin Web Plugin DB Plugin Mobile Plugin Runner Test Case
  7. 7. ProgressModule Test Runner Junit3 Framework Junit4 Framework 100% Database Test Plugin CXF Test Plugin RPC Test Plugin Web UI Test Plugin Http Test Plugin Mobile Test Plugin Business Modules Web App How we do? - Maven Projects 100% 100% 100% 100% 100% 100% 100% 0% 25% 25% Example/Demo 100%
  8. 8. 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
  9. 9. 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)
  10. 10. Scene – How to define Test Project Structure? Test Resource files (Test Config File) Junit4 Test Case Test Service API Log
  11. 11. Scene – How to Write a Spring Test Case? API public interface IHelloService { /** * @param name * @return */ public String hello(String name); } IMPL public 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; @Test public 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
  12. 12. 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>gmluyang@gmail.com</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, "gmluyang@gmail.com"); assertEquals(passwd, "xxxxxx"); } } 2 1 Tag Interface
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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", "gmluyang@gmail.com"); 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", "gmluyang@gmail.com"); 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
  17. 17. 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", "gmluyang@gmail.com"); loginPage.setHtmlInputValue(“Passwd”, "*"); // loginedPage IPage loginedPage = loginPage.onClick("signIn"); // assertEquals assertEquals(true, loginedPage.isElementTextContent("gbi4t", "Yang Lu"));
  18. 18. 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?
  19. 19. How to Run Test Case? – Eclipse IDE Local Debug
  20. 20. How to Run Test Case? – Maven Integration Test
  21. 21. How to Run Test Case? – WuKong Runner Test Classes Test XML File Test XML Element Test XML Text Runner API Run Test Programmatically using Java
  22. 22. 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 TestRunner TestCaseClassLoader - 2 Test-demo-2.0.0.jar
  23. 23. Demo - Web App : Login
  24. 24. Demo – Web App : How to Manage Test Case
  25. 25. Demo – Web App : How to watch Test Web-App JVM
  26. 26. Questions
  27. 27. Thank you

×