testing your app
TRANSCRIPT
TESTING YOUR APP
24-Feb-2016
Agenda
• Test levels & types• When to automate ?• Testing Tools• Testing Goals• Example: Business API• Example: Frontend• Conclusion
Really?
Test levels
Test types
• Installation• Compatibility• Smoke and Sanity checks• Regression• Acceptance• Destructive• Performance• Security
When to automate ?
Testing tools
• Runner: Junit, TestNG, …• Specification framework:
• Spock, Cucumber, …
• Grey Box testing (DISRUPTIONS !): • Arquillian, Pax-Exam, Spring-Boot integration tests, …
• Black Box testing:• UI: Selenium, Protractor, …• Messaging: Citrus but …, Camel, …• Production: Docker, kubernetes, vagrant, …
Testing Tools
• MOCK/STUB !• Simulation, but not only…• Expectations/Assertions !
• DO NOT USE CUSTOM MOCK !• Google: framework + mock
• Mockito, gwtmockito, angular-mock, …
• WARN: Conflicts in Continuous Integration
Testing Goal
• « A test must be checked by a machine ! »
• « A test must be expressive, showing what is going on, not how it’s going on ! »
Example: Business API
Client
Business API
Microservice A
Microservice B
Example: Business API
Client
Stub
Business API
Microservice A
Microservice B
1. Send request
Test
runn
erS
ystem under test
2. Check request
3. Save Replies
4. Check Reply
Example: Business API
• Stub: Apache Camel
from("netty4-http:http://0.0.0.0:{{local.http.port}}?matchOnUriPrefix=true") .to(MOCK_REQUEST_ENDPOINT) .choice() .when(method("mockResponseSupplier", "hasToUseMock").isEqualTo(false)) .setProperty(PROXY_TARGET, method("endpointResolver", "resolve")) .toD('${property.' + PROXY_TARGET + '}') .otherwise() .setHeader(Exchange.HTTP_RESPONSE_CODE, header(MOCK_RESPONSE_STATUS)) .process("mockResponseSupplier") .end() .convertBodyTo(String.class) .to(MOCK_RESPONSE_ENDPOINT)
Example: Business API
• Describe test as features
A client can retrieve customer’s accounts with arbitrary criterias given: A request uri
and: A setup to simulate replies if $mock is true
when: An http GET request is performed on $requestUri
then: A first request is sent to Microservice A to get the list of accounts
and: Microservice A responds with the list of accounts or an error
and: For each account in the list, a request is sent to Microservice B to get its expired balance and: Finally, a reply corresponding to the intercepted responses is sent back to the client. It can be an error or corresponding list of accounts. where:
Example: Business API
• Describe test as features• Spock framework
def "A client can retrieve customer’s accounts with arbitrary criterias"() { given: "A request uri" //groovy code and: "A setup to simulate replies if $mock is true" //groovy code
when: "An http GET request is performed on $requestUri" //groovy code
then: "A first request is sent to Microservice A to get the list of accounts" //groovy code and: "Microservice A replies with the list of accounts or an error" //groovy code and: "For each account in the list, a request is sent to Microservice B to get the expired balance" //groovy code and: "Finally, a reply corresponding to the intercepted responses is sent back to the client. It can be an error or corresponding list of accounts." where: //groovy code}
Example: Frontend
• Validations• Correct format / Correct data
• Behavior• Scripts
• Visual• CSS
Example: Frontend
<p> <label for="name">Nom <span class="red">*</span></label> <input id="name" name="contact.lastName" type="text" value="" maxlength="255"/></p><p> <label for="firstname">Prénom</label> <input id="firstname" name="contact.firstName" type="text" value="" maxlength="255"/></p>
Example: Frontend with Selenium
@Testpublic void testSelenium() throws Exception { driver.get(baseUrl + "/fr/become-customer.html?execution=e1s1"); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys("Boulanger"); driver.findElement(By.id("electricite")).click(); driver.findElement(By.id("gaz")).click(); driver.findElement(By.id("accept")).click(); driver.findElement(By.id("submit_button")).click();}
<tr> <td>open</td> <td>/fr/become-customer.html?execution=e1s1</td> <td></td></tr><tr> <td>type</td> <td>id=name</td> <td>Super</td></tr>
Speak the same language
What is a user story?
« Story »=
User ProblemWith acceptance criteria
Conclusion
• Testing strategy is a best practice• A lot of tools. We have to choose them and use them.• The more we do, the best we are.• Not only for developers but also for business (ex: Selenium)• Acceptance criteria help to target the testing• Acceptance criteria will define if the features is OK or not
Conclusions
Questions ?