Test Automation Hands On Lab
Use this lab time to create two types of test for the Demo Application
Part 1 Setup
- Checkout the Lesson-1 Tag of the CICDDemoApp
- Checkout a branch with the name “«YourName»-Unit-Test”
Part 1 End to End test using Cypress
N.B. Use the following commands to setup your environment for writing cypress tests:
docker-compose up -d express-api
vue-client/npm run test:e2e
This will start up the back end server in detached mode and will start the cypress tests
- Add the Cypress Vue Cli dev dependency to the project using
npm i --save-dev @vue/cli-plugin-e2e-cypress
- Add the Cypress-Axe Dev dependency to the project
Use the instructions found here: https://www.npmjs.com/package/cypress-axe
You will have to restart your cypress instance after this step - Write a test that adds a task and validates that it gets added
- Write a test that toggles the task you added in the previous step and validates that it gets toggled.
- Add the following to the
scripts
section of thevue-client/package.json
file.
"test:e2e-cli": "vue-cli-service test:e2e --headless --url http://localhost:8080 --config video=false,chromeWebSecurity=false",
This will run the cypress tests in headless mode, it disables video, and disables the Cross-Origin-Resource-Sharing Check. - Add the following Job to you azure-pipelines.yml file
- job: integration_tests
pool:
vmImage: 'Ubuntu-16.04'
dependsOn:
- build_containers
steps:
- task: DownloadPipelineArtifact@0
inputs:
targetPath: .
artifactName: images
- script: docker load < docker-images.tar
displayName: 'Loading Docker Images'
- script: docker-compose up -d express-api postgres-database vue-client
displayName: 'Start Backend'
- script: |
cd vue-client
npm ci
npm run test:e2e-cli
displayName: 'Run Test'
Part 2 Unit Tests
- Add Nock to your project as a dev tool
npm i --save-dev nock
- Use nock and jest to write an automated unit test for the mounted method in the
home.vue
file. The test should do the following:- Setup the nock mock
- run the mounted method
- verify that the mocked tasks get added to the tasks property
- Add unit test to vue-client docker build by adding the following line in the build stage after
npm ci
is run:RUN npm run test:unit
Part 3 Finish up
- Commit your changes
- Push your branch up to GitHub
- Open a Pull Request to kick off the build