Good Practices On Test Automation
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Good Practices On Test Automation

on

  • 737 views

presentation on 54th SPIN-Campinas meeting.

presentation on 54th SPIN-Campinas meeting.
(http://www.cpqd.com.br/spin-cps/index.php?option=com_content&task=archivecategory&year=2013&month=03&module=1)

Statistics

Views

Total Views
737
Views on SlideShare
735
Embed Views
2

Actions

Likes
0
Downloads
5
Comments
0

1 Embed 2

http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Good Practices On Test Automation Presentation Transcript

  • 1. Good practices on test automation Gustavo Labbate Godoy
  • 2. Where are test automation on agile environments? Several agile methodologies: Scrum, Extreme Programming (XP), Lean Development, Feature- Driven Development (FDD), Kanban, RUP and OpenUP. Software Development by interactive and incremental way. TDD, Data-Driven Testing, Regression Testing. Automation is one of the three pilars of agile methodology. Delivery on time, with all tested and approved. “Working software is the primary measure of progress.” (http://agilemanifesto.org)
  • 3. Junit is unit test ?
  • 4. What is unit test and what is Junit ? Unit test Test the smaller of the components in a isolated way. Test methods must be independent. Functional test Test the behavior of the sistem, from data inputs, processing and data outputs. assertEquals( ExpectedResult, returnProcessedData(entryData) );assertEquals( ExpectedResult, returnProcessedData(entryData) ); returnedObject = insertData(entryData); assertNotNull(returnedObject); //Validating if insert was sucessfull consultedObject = consultData(returnedObject); assertEquals( consultedObject, expectedObject ); //Validating if insert was sucessfull through system query returnedObject = insertData(entryData); assertNotNull(returnedObject); //Validating if insert was sucessfull consultedObject = consultData(returnedObject); assertEquals( consultedObject, expectedObject ); //Validating if insert was sucessfull through system query
  • 5. Correctly specify your tests
  • 6. Correctly specify your tests Don't say test, be more specific ... TestCalculate - testCalc1 = shouldSumTwoInt - testCalc2 = shouldSubtractFromSum Test all functionality inside your method (avoid alphabetical ordering). expectedObjects = testParameters; expectedObjects = includeData(entryData); assertNotNull(returnedObject); //Validating if insert was sucessfull consultedObject = consultData(returnedObject); assertEquals( consultedObject, expectedObject ); //Validating if insert was sucessfull through system query expectedObjects = testParameters; expectedObjects = includeData(entryData); assertNotNull(returnedObject); //Validating if insert was sucessfull consultedObject = consultData(returnedObject); assertEquals( consultedObject, expectedObject ); //Validating if insert was sucessfull through system query
  • 7. Correctly specify your tests But ... @Test public void shouldSucessfulyInclude() { … } @Test public void shouldSucessfullyConsultAfterInclude() { … } @Test public void shouldSucessfulyInclude() { … } @Test public void shouldSucessfullyConsultAfterInclude() { … } @FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @Test public void aShouldSucessfulyInclude() { … } @Test public void bShouldSucessfullyConsultAfterInclude() { … } @Test public void aShouldSucessfulyInclude() { … } @Test public void bShouldSucessfullyConsultAfterInclude() { … } Alphabetically ordering methods: Every test method must be independent. Execution order is random.
  • 8. Parameterize test data Read from a spreadsheet (or another external file … ) @RunWith(Parameterized.class) public Class UserInsert @Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[][] {{"ParameterA"}, {"ParameterB"}} ); } public UserInsert(String[ ] parameters) { /* Add parameters to variables ... */ } @RunWith(Parameterized.class) public Class UserInsert @Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[][] {{"ParameterA"}, {"ParameterB"}} ); } public UserInsert(String[ ] parameters) { /* Add parameters to variables ... */ } https://bitbucket.org/wakaleo/jxlunit/src/6eb465c848c8/src/main/java/com/wakaleo/training/jxlunit/SpreadsheetData.java @Parameters public static Collection spreadSheetData() throws IOException { InputStream spreadSheet = new FileInputStream(“mySheet.xls”); return new SpreadSheetData(spreadSheet).getData(); } @Parameters public static Collection spreadSheetData() throws IOException { InputStream spreadSheet = new FileInputStream(“mySheet.xls”); return new SpreadSheetData(spreadSheet).getData(); }
  • 9. Selenium
  • 10. Selenium IDE or Core ? IDE • Record & Playback • Export to several languages (C#, Java, Perl, PHP, Python, Ruby). • In browser test execution. • Code refactoring: Re-record your tests... • To avoid: use plugins (do a little programming … ) • Record only on firefox, but run on others (the script, not in IDE … ) • Don't need advanced knowledge on exported code. Core (coding) • API to several languages (C#, Java, Perl, PHP, Python, Ruby). • Build your own test framework, extending selenium. • Test execution on several browser. • Code refactoring: update only affected test code (Page Object Model) • Knowledge of choosen language is essential.
  • 11. Promote maintainability
  • 12. Promote maintainability Use fixtures WebDriver driver @BeforeClass public static void runBeforeClass() throws Exception { driver = new FirefoxDriver(); selenium = new WebDriverBackedSelenium(driver, url); capability = DesiredCapabilities.firefox(); capability.setBrowserName("firefox"); capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true); } @After public void runAfterEachTest() { printScreen(); } @AfterClass public static void runAfterClass() { driver.quit(); } WebDriver driver @BeforeClass public static void runBeforeClass() throws Exception { driver = new FirefoxDriver(); selenium = new WebDriverBackedSelenium(driver, url); capability = DesiredCapabilities.firefox(); capability.setBrowserName("firefox"); capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true); } @After public void runAfterEachTest() { printScreen(); } @AfterClass public static void runAfterClass() { driver.quit(); }
  • 13. Promote maintainability PageObjects Object that represents a web system screen. public Class LoginPO @FindBy(id="user") WebElement user; @FindBy(id="password") WebElement password; @FindBy(id="btnClose") WebElement closeButton; @FindBy(id="btnLogin") WebElement loginButton; String userAcessApp = "automation"; String passwordAcessApp = "selenium"; public void typeAndEnter(String user, String pass) { usuer.sendKeys(user); password.sendKeys(pass); loginButton.click(); } public Class LoginPO @FindBy(id="user") WebElement user; @FindBy(id="password") WebElement password; @FindBy(id="btnClose") WebElement closeButton; @FindBy(id="btnLogin") WebElement loginButton; String userAcessApp = "automation"; String passwordAcessApp = "selenium"; public void typeAndEnter(String user, String pass) { usuer.sendKeys(user); password.sendKeys(pass); loginButton.click(); }
  • 14. Organize …
  • 15. Organize ... Using Junit Test Suite @RunWith(Suite.class) @SuiteClasses({ TestClass1.class, TestClass2.class, TestClass3.class }) public class AllMyTests { } @RunWith(Suite.class) @SuiteClasses({ TestClass1.class, TestClass2.class, TestClass3.class }) public class AllMyTests { }
  • 16. Solid foundations ...
  • 17. Solid foundations ... Guarantees data integrity Spring's configuration: <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${hibernate.connection.driver_class}" /> <property name="url" value="${hibernate.connection.url}" /> <property name="username" value="${hibernate.connection.username}" /> <property name="password" value="${hibernate.connection.password}" /> </bean> Spring's configuration: <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${hibernate.connection.driver_class}" /> <property name="url" value="${hibernate.connection.url}" /> <property name="username" value="${hibernate.connection.username}" /> <property name="password" value="${hibernate.connection.password}" /> </bean> DBUnit's dataSet to setup and prepare a data base <dataset> <schema.USER LOGIN="User" PASSWORD="781b4ea1d8" NAME="Test User" PASSWORD_EXPIRATION_DATE="2013-03-01 00:00:00.0" LOGIN_COUNT="0" EMAIL="user@test.com" /> </dataset> DBUnit's dataSet to setup and prepare a data base <dataset> <schema.USER LOGIN="User" PASSWORD="781b4ea1d8" NAME="Test User" PASSWORD_EXPIRATION_DATE="2013-03-01 00:00:00.0" LOGIN_COUNT="0" EMAIL="user@test.com" /> </dataset>
  • 18. Orchestrate ...
  • 19. Orchestrate ... Manage automated executions
  • 20. Orchestrate ... Manage test execution results
  • 21. References Arquillian http://arquillian.org/ Junit http://junit.sourceforge.net/ Selenium http://seleniumhq.org/ DBUnit www.dbunit.org/ Page Objects https://docs.jboss.org/author/display/ARQGRA2/Page+Objects http://code.google.com/p/selenium/wiki/PageObjects Jenkins http://jenkins-ci.org/ TestLink http://www.teamst.org/
  • 22. Thanks! gustavolabbate@gmail.com linkedin.com/in/gustavolabbate @gustavolabbate