DDSteps使用例子


Certified Java Professionals Agile Testing of Whole Web Applications Adam Skogman Project Lead, DDSteps Senior Java EE Consultant, Jayway AB Certified Java Professionals 2 DDSteps in 1-2-3 Data Driven Repeat Test with Different Data Killer App Web + Database Testing 100% JUnit Compatible Already Integrated Teaser Trailer Data Driven Testing Certified Java Professionals 4 Unit Testing in LdapTemplate # , + " \ / < > ; \# \, \+ \" \\ \/ \< \> \; public void testNameEncode_old() { nameEncode( "# , + \" \\ / < > ;"); assertEquals("\\# \\, \\+ \\\" \\\\ \\/ \\< \\> \\;"… } public void testNameEncode() throws Exception { nameEncode(plain); assertEquals(encoded, x); } DDSteps Demo It's Just a Couple of .jars in your Classpath Certified Java Professionals 6 When to Use DDSteps Unit Test TestCase Class Under Test Mock Objects Mock Objects Function Test Integration Unit Test TestCase Class Under Test Other Class Other Class Certified Java Professionals 7 Waterfall is so '80s Req. Develop Unit Test Function Test Live! Acc. Test Certified Java Professionals 8 Bugs? Who knew... Req. Develop Unit Test Function Test L Pre-Test Fix Re-Test Fix Re-Test Certified Java Professionals 9 DDSteps is Agile Req. Develop Unit Test Function Test Live!Acc. Test Req. Develop Unit Test Function Test Live!Acc. Test Req. Develop Unit Test Function Test Live!Acc. Test 9 weeks 3 w Certified Java Professionals 10 DDSteps is Continuous Integration Implement Commit Detect Changes Run tests BuildUnit Test Deploy Function Test Tag Update Certified Java Professionals 11 Guest Staring: Pet Clinic Example from the Spring Framework™ Out ofthe Box! Certified Java Professionals 12 It’s just Complicated Add New Pet (OK) 1. Log in 2. Click “Find Owner” 3. Click “Find Owners” 4. Click “Charlie Brown” 5. Click “Add New Pet” 6. Validate defaults 7. Enter data 1. “Snoopy” 2. “1969-01-13” 3. “Dog” 8. Click “Add Pet” 9. Validate owner page 10. Validate database 111969-01-13Snoopy42 OWNER_IDTYPE_IDBIRTH_DATENAMEID DDSteps Software Engineering Certified Java Professionals 14 1. Pull Out the Data Add New Pet (OK) 1. Log in 2. Click “Find Owner” 3. Click “Find Owners” 4. Click “Charlie Brown” 5. Click “Add New Pet” 6. Validate defaults 7. Enter data 1. “Snoopy” 2. “1969-01-13” 3. “Dog” 8. Click “Add Pet” 9. Validate owner page 10. Validate database Properties „ Owner Full Name „ Pet Name „ Pet Birth Date „ Pet Type Data duplication! Certified Java Professionals 15 Put it in a Spreadsheet Sheet Name = Method Name One File = One JUnit Test Case One Row = One Run Header = Property File name 1:1 Class Name Certified Java Professionals 16 2. Break up the Test into steps Add New Pet (OK) 1. Log in 2. Click “Find Owner” 3. Click “Find Owners” 4. Click Owner 5. Click “Add New Pet” 6. Validate defaults 7. Enter data 1. Pet Name 2. Pet Birthdate 3. Pet Type 8. Click “Add Pet” 9. Validate owner page 10. Validate database Navigators „ Gets you there „ Composites Executors „ Enter input Validators „ Check output Certified Java Professionals 17 Add Pet - OK Tests from Test Steps NavigateToAddPet NavigateToOwner ExecuteAddPet ValidatePetOnOwnerPage ValidatePetRow ValidatePetForm NavigateToFindOwner ExecuteFindOwner Add Pet - Fail NavigateToAddPet ExecuteAddPet ValidatePetErrorMsg ValidateNoPetRow ValidatePetForm Certified Java Professionals 18 3. DbUnit Fixture Data First Row = Column Name Sheet Name = Table Name Excel Ranges Certified Java Professionals 19 The Big Picture Certified Java Professionals 20 Problem Solved Data Driven Repeat Tests with Different Data Test Steps Test Composition & Reuse Fixtures Powerful Base Data Management Bits and Bytes Integrating the Best-of-Breed Certified Java Professionals 22 JUnit™ Eclipse™ Ant MavenIntelliJ IDEA™ Cruise Control AntHill™ Gump Continuum DDSteps is Already Integrated JUnit™ Eclipse™ Ant MavenIntelliJ IDEA™ Really Expensive™ Test Tool Cruise Control AntHill™ Gump Continuum Certified Java Professionals 23 Testing with DDSteps Certified Java Professionals 24 Web Browser API jwebunit.sourceforge.net httpunit.sourceforge.net www.openqa.org/selenium/ JMeter Some Tool HTTP HTTP HttpUnit HTTP TestCase API JWebUnit HTTP TestCase API Selenium, HtmlUnit… Certified Java Professionals 25 Web Browser API Navigate clickLinkWithText("Find owner"); clickLinkWithImage("...next.png"); Execute setFormElement("name", "Snoopy"); selectOption("type", "Dog"); checkCheckbox("fictional"); clickButton("Add"); submit("Finish"); Validate assertTitleEquals("Login Page"); assertFormElementEquals("name","Snoopy"); assertTextInElement("owner", "Charlie Brown"); Certified Java Professionals 26 Web TestStep public class ExecuteAddPet extends WebBrowserTestStep { protected String name; public void setName(String name){...} public void runStep() throws Exception { setFormElement("name", name); setFormElement("birthDate", birthdate); selectOption("typeId", type); submit(); writeTrail("After Execute Add Pet"); } Certified Java Professionals 27 DbUnit and Spring JDBC JDBCTestCase API DbUnit JDBCTestCase API Spring JDBC www.dbunit.org www.springframework.org Certified Java Professionals 28 Spring JDBC Validator public ValidatePetRow(DataSource ds) { super(ds, "select * from PETS where NAME = ?"); ... } protected void validateRow(ResultSet rs, int rowNum) … { assertEqual(ownerId, rs.getInt("OWNER_ID")); assertDatesEqual(birthdate, rs.getDate("BIRTH_DATE")); ... } protected void validateRow(ResultSet rs, int rowNum) … { assertEqual(ownerId[rowNum], rs.getInt("OWNER_ID")); assertDatesEqual(birthdate[rowNum], rs.getDate("BIRTH_DATE")); ... } protected void validateRowCount(int numRows) { assertEquals(1, numRows); } Just likeMapping-SqlQuery Certified Java Professionals 29 Testing with DDSteps Certified Java Professionals 30 The TestCase public class PetFTest extends DDStepsSpringTestCase { protected NavigateToAddPet nav; protected ValidatePetForm valForm; protected ExecuteAddPet exeAddPet; protected ValidatePetOnOwnerPage valOwnerPage; protected ValidatePetRow valRow; public NavigateToAddPet getNav(…) {…} public void setNav(…) {…} public void testAddPet_Ok() throws Exception { nav.runStep(); valForm.runStep(); exeAddPet.runStep(); valOwnerPage.runStep(); valRow.runStep(); } Certified Java Professionals 31 JavaBean Expression Language PetFTest DDStepsSpringTestCase # nav : NavigateToAddPet # valForm : ValidatePetForm # exeAddPet : ExecuteAddPet # valRow : ValidatePetRow + testAddPet_Ok() + getNav() : NavigateToAddPet + getValForm() : ValidatePetForm + getExeAddPet() : ExecuteAddPet + getValRow() : ValidatePetRow SpringJdbcValidator ValidatePetRow # name : String # birthDate : java.sql.Date # typeId : int # ownerId : int + runStep() + setName(String) + setBirthDate(Date) + setOwnerId(int) + setOwnerId(int) Column Header: valRow.name Web App Testing Demo DDSteps, PetClinic and Eclipse Certified Java Professionals 33 Spring Framework™ Powered PetFTest ddsteps-context.xml ValidatePetRow DataLoader FixtureLoader DataSource DDSpring TestCase Env. Config WebBrowser NavigateToAddPet ValidatePetForm ExecuteAddPet ValidatePetOn OwnerPage Certified Java Professionals 34 Open API:s Open API „ TestStep „ DataLoader „ FixtureLoader Insert Your Technology Here… „ EJBs „ Web Services „ Proprietary „ Legacy Working with DDSteps Certified Java Professionals 36 Agile & Continuous Testing Domain: „ Test Cases „ Test Steps „ Data Refactored Test Steps Technical: „ Test Cases „ Test Steps „ Data Tester Programmer Project Leader Test Report Project Status Certified Java Professionals 37 Real Regression Testing Development Project Test Staging Production Development Project Test Staging Production Certified Java Professionals 38 DDSteps handles Large Projects DDSteps Scales Well „ 3000+ Unit Tests „ 300+ Function Tests Layered Fixtures Layered Test Suites „ Smoke Tests „ Daily/Nightly Builds Ant Utils (1.x) DDSteps1.2 Surprise! Bonus Demo Summary Yes, it's Open Source! Certified Java Professionals 41 DDSteps is Open Source Lesser GNU Public License „ No Evil Commercial Forks „ Open Co-Operation „ No ”Class Path Exception” Needed Professional Software „ Backed by Jayway „ Supported by Jayway „ Dedicated Developers „ Active Customers „ Active Users Certified Java Professionals 42 DDSteps Community Tracking & Planning jira.ddsteps.org Web & Community www.ddsteps.org SourceForge ddsteps-user@lists.sourceforge.net Certified Java Professionals 43 DDSteps Releases Pre-release 1.1.1 „ Eclipse 3.2 Release 1.1 „ June 2006 „ LDAP „ Community „ Documentation „ Courtesy Classes „ Samples Release 1.0 „ September 2005 1.x Series „ Large Projects „ Selenium™ „ HttpUnit 2.0 „ OpenOffice™ 2.x Series „ Smart Clients „ Java ME™ „ JMS „ XML Data Loading „ JUnit 4 „ TestNG Certified Java Professionals Q & A www.ddsteps.org www.jayway.se 45 Certified Java Professionals www.jayway.se
还剩44页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 8 金币 [ 分享pdf获得金币 ] 0 人已下载

下载pdf

pdf贡献者

tttti

贡献于2011-12-17

下载需要 8 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf