The Tutorial

Reviews
Shared by: techmaster
Categories
Stats
views:
235
rating:
not rated
reviews:
0
posted:
10/29/2008
language:
English
pages:
0
The Tutorial www.ddsteps.org Data Driven Tutorial Adam Skogman Björn Granvik We Have a Dream The Best Laid Plans... Req. Develop Unit Test Function Test Acc. Test Live! Then, Reality Happens... Req. Develop Unit Test Pre-Test Function Test Acc. Test Live! Bugs? Who knew... Req. Develop Unit Test Pre-Test Function Test Fix Re-Test Fix Re-Test L Go Agile! 9 weeks Develop Req. 3w Req. Unit Test Function Test Develop Unit Test Acc. Test Acc. Test Live! Live! Function Test Develop Req. Unit Test Function Test Acc. Test Live! Circle of Life Tag Function Test Deploy Update Implement Run tests Commit Detect Changes Unit Test Build Our Dream Continuous Everything Zero Known Defects at Release Known Project Progress Transparent Project Status Use Case Coverage What's the Problem, Anyway? Guest Starring: Pet Clinic www.springframework.org It’s just Complicated Add New Pet (OK) 1. 2. 3. 4. 5. 6. 7. Log in Click “Find Owner” Click “Find Owners” Click “Charlie Brown” Click “Add New Pet” Validate defaults Enter data 1. 2. 3. “Snoopy” “1950-10-02” “Dog” ID 42 NAME Snoopy BIRTH_DATE 1969-01-13 TYPE_ID 1 OWNER_ID 1 8. 9. 10. Click “Add Pet” Validate owner page Validate database Why is Function Testing so Hard? Functions testAddPet_Ok testAddPet_Fail Combinations testAddPet_Ok_Harvey testAddPet_Ok_Hobbes testAddPet_Ok_Woodstock testAddPet_Ok_Snoopy testFindOwner_Ok testFindOwner_Fail testFindVet_Ok Hello DDSteps! Yes, it's Open Source! 1. Pull Out the Data Add New Pet (OK) 1. 2. 3. 4. 5. 6. 7. Properties     Log in Click “Find Owner” Click “Find Owners” Click “Charlie Brown” Click “Add New Pet” Validate defaults Enter data 1. 2. 3. Owner Full Name Pet Name Pet Birthdate Pet Type “Snoopy” “1969-01-13” “Dog” 8. 9. 10. Click “Add Pet” Validate owner page Validate database Data reuse Put it in a Spreadsheet One File = One JUnit Test Case Header = Property File name 1:1 Class Name One Row = One Run Sheet Name = Method Name Data Driven Test Case Basic example   Data and Code separation Setting JavaBeans properties Does not use    Test Steps Fixtures Spring Example: Compare strings The Method Under Test public class StringComparator { public boolean compare(String one, String two) { ... } } JUnit is Everywhere JUnit Eclipse IntelliJ IDEA Ant Maven Expensive Test Tool Cruise Control AntHill Gump Continuum The Old Way public public public public public public public public ... void void void void void void void void testCompare() {...} testCompareDifferentOrder() {...} testCompareSwedishCharacters() {...} testCompareSmallCharacters() {...} testCompareCaseInsensitive() {...} testCompareStrangeCharacters() {...} testCompareNull() {...} testCompare...() {...} The Data Driven Way Strings to compare Colors, just for our own pleasure. Delimit Data using Data and "---" Properties using "---" The Test public class DdStringComparatorTest extends DdTestCase { private String one; private String two; private boolean result; public void setOne(String one) { … } public void testCompare() { StringComparator tested = new StringComparator(); boolean actual = tested.compare(one, two) assertEquals(result, actual); } protected DataLoader createDataLoader() { return CachingExcelDataLoader.getInstance(); } (Backup) Keep the matrix green! (Backup) The Bug public class StringComparator { ... public boolean compare(String one, String two) { return one.equals(two); } } Let's fix it! (Backup) Fixed code public boolean compare(String one, String two) { if (one == null) { return false; } return one.equalsIgnoreCase(two); } (Backup) Result (Backup) ÅÄÖ? Still fine Summary Test Driven Too Easy? Can Do a Lot   Unit Testing Integration Testing Loads of Opportunities Testing Web Applications PetClinic from Above JWebUnit HTTP HTTP HTTP API JWebUnit HttpUnit JMeter Some Tool TestCase jwebunit.sourceforge.net httpunit.sourceforge.net JWebUnit API Navigate webBrowser.clickLinkWithText("Find owner"); webBrowser.clickLinkWithImage("...next.png"); Execute webBrowser.setFormElement("name", "Snoopy"); webBrowser.selectOption("type", "Dog"); webBrowser.checkCheckbox("fictional"); webBrowser.clickButton("Add"); webBrowser.submit("Finish"); Validate webBrowser.assertTitleEquals("Login Page"); webBrowser.assertFormElementEquals("name","Snoopy"); webBrowser.assertTextInElement( "owner","Charlie Brown"); JWebUnit – Start Here Code WebBrowser webBrowser = new WebBrowser(); webBrowser.setUrl(“http://localhost:8080”); webBrowser.beginAt("/"); webBrowser.clickLinkWithText("Find owner"); JWebUnit - Choose a Form HTML ... Code setWorkingForm(owner); submit(); Data owner = "Charlie Brown" JWebUnit – Click "Add New Pet" Same, same JWebUnit - Entering Data HTML
... Name: ... Code setFormElement("name", name); setFormElement("birthDate", birthdate); Data name = "Snoopy" birthdate = "1969-01-13" JWebUnit - Drop Box HTML Code selectOption("typeId", type); Data type = "Dog" JWebUnit - Validating HTML Code assertTextPresent("Owner Information"); assertTextPresent("Pets and Visits"); assertTablePresent(name); assertTextInTable(name, name); assertTextInTable(name, birthdate); assertTextInTable(name, type); Data name = "Snoopy" birthdate = "1969-01-13" type = "Dog" Database Testing PetClinic from Below DbUnit and Spring JDBC API API TestCase DbUnit JDBC TestCase Spring JDBC JDBC www.dbunit.org www.springframework.org Spring JDBC Validator Table ID 42 NAME Snoopy BIRTH_DATE TYPE_ID OWNER_ID 1969-01-13 1 1 Code (part 1) public class ValidatePetRow extends SpringJdbcValidator { public ValidatePetRow(DataSource ds) { super(ds, "select * from PETS where NAME = ? and OWNER_ID = ?"); declareParameter(new SqlParameter(Types.VARCHAR)); declareParameter(new SqlParameter(Types.INTEGER)); compile(); } Spring JDBC Validator protected Object[] assembleParameters() { return new Object[] { name, new Integer(ownerId) }; } protected void validateRow(ResultSet rs, int rowNum) … { … DateAssert.assertDatesEqual("Wrong birthdate. ", birthdate, rs.getDate("BIRTH_DATE")); Assert.assertEquals("Wrong pet type", typeId, rs.getInt("TYPE_ID")); } protected void validateRowCount(int numRows) { Assert.assertEquals( "There should be one and only one pet row.", 1, numRows); } DbUnit Fixture Data First Row = Column Name Excel Ranges Sheet Name = Table Name TestSteps Or, what's up with that name, anyway? Test Steps Add New Pet (OK) 1. 2. 3. 4. 5. 6. 7. 8. Navigators   Log in Click “Find Owner” Enter Owner Lastname Click “Find Owners” Click Owner Click “Add New Pet” Validate defaults Enter data 1. 2. 3. Gets you there Composites Enter input Check output Executors  Validators  Pet Name Pet Birthdate Pet Type Click “Add Pet” 10. Validate owner page 11. Validate database 9. Tests from Test Steps PetFTest.testAddPet_Ok() NavigateToAddPet ValidatePetForm ExecuteAddPet ValidatePetOnOwnerPage ValidatePetRow NavigateToFindOwner ExecuteFindOwner NavigateToOwner PetFTest.testAddPet_Fail() NavigateToAddPet ValidatePetForm ExecuteAddPet ValidatePetErrorMsg ValidateNoPetRow JavaBeans JWebUnitTestStep DdSpringTestCase SpringJdbcValidator PetFTest # nav : NavigateToAddPet # valForm : ValidatePetForm # exeAddPet : ExecuteAddPet # valRow : ValidatePetRow + testAddPet_Ok() ValidatePetRow # name : String # birthdate : java.sql.Date # typeId : int # ownerId : int + runStep() + getNav() : NavigateToAddPet + getValForm() : ValidatePetForm + getExeAddPet() : ExecuteAddPet + getValRow() : ValidatePetRow + setName(String) + setBirthdate(Date) + setTypeId(int) + setOwnerId(int) valRow.birthdate Column Header: valRow.name valRow.typeId DDSteps Springing It Together The Big Picture Spring Context DDSpring TestCase DataLoader FixtureLoader PetFTest ValidatePetRow NavigateToAddPet ValidatePetForm ExecuteAddPet DataSource ValidatePetOn OwnerPage WebBrowser DDSpringTestCase Flow 1. Spring Dependency Injection 2. Call setUpMethod() 3. Run "Excel Row 8" 1. 2. 3. 4. Call setUpBeforeData() DDSteps Property Injection Call setUpAfterData() Call testAddPet_Ok() Call tearDownBeforeData() 5. 4. Run "Excel Row 9" 5. … 6. Call tearDownMethod() The TestCase public class PetFTest extends DdSpringTestCase { protected protected protected protected protected NavigateToAddPet nav; ValidatePetForm valForm; ExecuteAddPet exeAddPet; ValidatePetOnOwnerPage valOwnerPage; ValidatePetRow valRow; public void setNav(…) {…} public void testAddPet_Ok() throws Exception { nav.runStep(); valForm.runStep(); exeAddPet.runStep(); valOwnerPage.runStep(); valRow.runStep(); } Filling the Database protected FixtureLoader fixtureLoader; public void setFixtureLoader(...) {...} protected Fixture fixture; public void setUpMethod() throws Exception { fixture = fixtureLoader.loadFixture(this); fixture.setUp(); // DB is now filled with data } public void tearDownMethod() throws Exception { fixture.tearDown(); fixture = null; } A Navigator TestStep public class NavigateToAddPet extends JWebUnitTestStep { protected NavigateToOwner navigateToOwner; public NavigateToAddPet(WebBrowser webBrowser) { super(webBrowser); navigateToOwner = new NavigateToOwner(webBrowser); } public void runStep() throws Exception { navigateToOwner.runStep(); setWorkingForm("formAddPet"); submit(); assertTextPresent("New Pet"); writeTrail("Add New Pet Form"); } Spring Context Spring Context DDSpring TestCase DataLoader PetFTest Data Loader ddsteps-context.xml ... Database Stuff Spring Context DDSpring TestCase DataLoader FixtureLoader PetFTest DataSource Data Source ... FixtureLoader ... OWNERS, TYPES, PETS, VETS, SPECIALTIES, VET_SPECIALTIES, VISITS Database Stuff Spring Context DDSpring TestCase DataLoader FixtureLoader PetFTest ValidatePetRow NavigateToAddPet ValidatePetForm ExecuteAddPet DataSource ValidatePetOn OwnerPage WebBrowser TestSteps ... Adapt to your Environment ddsteps-context.properties jdbc.driverClassName=org.hsqldb.jdbcDriver jdbc.url=jdbc:hsqldb:hsql://localhost:9001 jdbc.username=sa jdbc.password= url=http://localhost:8080/petclinic trails=C:\trails Best Practices Make sure you can Reuse   Executors don't assert Validators assert Write trails Data is Cheap    Happy flow Bad data Empty data Comment data rows One database per developer Gotchas Excel Column ≠ JavaBean Property   Bad Column Header? Missing Property? 'F5' in Eclipse to refresh workspace Everyday Life ...and how DDSteps will affect it Cruise Control Tag Function Test Deploy Update Implement Run tests Commit Detect Changes Unit Test Build Working With Data Driven Testing • Domain: • Test Cases • Test Steps • Data • Refactored Test Steps • Technical: • Test Cases • Test Steps • Data Tester Programmer • Test Report • Project Status Project Leader Real Regression Testing Development Project Test Environment Staging Production Community www.ddsteps.org jira.ddsteps.org DDSteps Roadmap Release 1.0  1.x Series   Out in September Release 1.1        Community Documentation Courtesy Classes Smart Clients? JMS? LDAP? AJAX Support? HtmlUnit? OpenOffice? 2.x Series   JUnit 4? TestNG? Q&A www.ddsteps.org Lab! Let's try DDSteps My First DDSteps TestCase public class StringComparator { public boolean compare(String one, String two) { ... } } Brainstorm!
Related docs
Tutorial Tutorial
Views: 284  |  Downloads: 7
Tutorial Tutorial
Views: 302  |  Downloads: 23
�Tutorial Tutorial�
Views: 174  |  Downloads: 12
TUTORIAL TUTORIAL
Views: 559  |  Downloads: 12
Tutorial
Views: 47  |  Downloads: 4
TUTORIAL
Views: 28  |  Downloads: 1
Tutorial
Views: 23  |  Downloads: 0
Tutorial
Views: 44  |  Downloads: 1
Tutorial
Views: 123  |  Downloads: 20
Tutorial A
Views: 252  |  Downloads: 5
TUTORIAL FOR THE
Views: 20  |  Downloads: 0
Tutorial
Views: 263  |  Downloads: 12
Tutorial
Views: 129  |  Downloads: 11
premium docs
Other docs by techmaster
Gustavus_Hindman_Miller_-_What's_In_A_Dream
Views: 50  |  Downloads: 1
The Art of True Healing[1]
Views: 115  |  Downloads: 13
d6391
Views: 18  |  Downloads: 0
How Specialists Destroy Their Lives
Views: 139  |  Downloads: 0
TourismProductSystem
Views: 450  |  Downloads: 15
Machinery Principle4[1]
Views: 76  |  Downloads: 11
Start Up Pitch Presentation
Views: 5071  |  Downloads: 544
ADA Side-By-Side Comparison Form
Views: 406  |  Downloads: 5
Tools For Success
Views: 318  |  Downloads: 29
Daily Mirror _1914_ - Mrs Pankhurst
Views: 49  |  Downloads: 12
current_regulation
Views: 86  |  Downloads: 1


NameSnoopy
Birth Date1969-01-13
TypeDog