This workshop will cover some techniques and tools that allow us to apply test automation to perform regression testing in a system. Nowadays, any software project needs to have automated tests that guarantee that the main functionality does not break during the development lifecycle. In this workshop we will focus on how to achieve this, by writing some automated tests for the APIs and GUI using the PetClinic application (https://github.com/spring-projects/spring-petclinic).
- Laptop
- Java (https://www.java.com/en/download/)
- Maven (https://maven.apache.org/install.html)
- Docker (https://docs.docker.com/v17.12/install/ check the tab 'DockerCE' on the left bar of the site for different OS versions)
- Chrome (https://www.google.com/chrome/)
- IDE (recommended https://www.jetbrains.com/idea/download/ or https://www.eclipse.org/downloads/)
Make sure you have Java 8 or later on your local development machine.
java -version
Make sure you have Maven 3.X on your local development machine.
mvn -v
Make sure you have Docker on your local development machine.
docker -v
Verify that everything works by running:
git clone https://github.com/feedzai/first-system-test-workshop
cd first-system-test-workshop
mvn clean install
Ensure that there were no failures. It means that you were able to launch test-containers and run a test against it.
If there are any questions or issues in the setup, feel free to email me: [email protected]
Run the following command:
docker run -dit -p 8080:8080 --name petclinic arey/springboot-petclinic
Lets start by doing it manually in Chrome:
- Open the browser and navigate to the PetClinic homepage at http://localhost:8080
- Open the Chrome Dev Tools in the Network tab
- Fill the user form and submit. The body from the POST request to create the owner should be similar to:
{
"firstName":"John",
"lastName":"Dow",
"address":"Instituto Pedro Nunes",
"city":"Coimbra",
"telephone":"200000000",
}
Now in the project open the PetClinicApiTest
class and add a new test that adds a new owner to PetClinic:
- Create a
post
andaddOwner
method inPetclinicApi
class - Add a parameter body in
addOwner
with typeObject
- Create a new test calling that endpoint, pass a map in the body parameter with the structure from the json above
5 - Enable the PetClinicApiTest
to run against Test Containers instead of a already running container
mvn clean install
- Test Containers (https://www.testcontainers.org/)
- Rest Assured (http://rest-assured.io/)
- Docker (https://github.com/wsargent/docker-cheat-sheet)
- Selenide (https://selenide.org/)
- Selenium (https://www.seleniumhq.org)
- Test Levels and Approach to automation (https://martinfowler.com/articles/practical-test-pyramid.html)
- Rules for writting automated tests (https://devops.com/10-rules-for-writing-automated-tests)