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)
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
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();
}
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.
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
{
}