testing your app

21
TESTING YOUR APP 24-Feb-2016

Upload: arnaud-deprez

Post on 14-Apr-2017

168 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Testing your app

TESTING YOUR APP

24-Feb-2016

Page 2: Testing your app

Agenda

• Test levels & types• When to automate ?• Testing Tools• Testing Goals• Example: Business API• Example: Frontend• Conclusion

Page 3: Testing your app

Really?

Page 4: Testing your app

Test levels

Page 5: Testing your app

Test types

• Installation• Compatibility• Smoke and Sanity checks• Regression• Acceptance• Destructive• Performance• Security

Page 6: Testing your app

When to automate ?

Page 7: Testing your app

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, …

Page 8: Testing your app

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

Page 9: Testing your app

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 ! »

Page 10: Testing your app

Example: Business API

Client

Business API

Microservice A

Microservice B

Page 11: Testing your app

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

Page 12: Testing your app

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)

Page 13: Testing your app

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:

Page 14: Testing your app

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}

Page 15: Testing your app

Example: Frontend

• Validations• Correct format / Correct data

• Behavior• Scripts

• Visual• CSS

Page 16: Testing your app

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>

Page 17: Testing your app

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>

Page 18: Testing your app

Speak the same language

Page 19: Testing your app

What is a user story?

« Story »=

User ProblemWith acceptance criteria

Page 20: Testing your app

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

Page 21: Testing your app

Questions ?