Testing and CI - Leonhest/Smartmat GitHub Wiki
Backend test are performed using three different test models:
- Unit tests using JUnit 5.
- Integration tests using a test H2 database.
- Mock testing with MockMvc.
In our app the unit tests are performed on the model classes with directly mapped to the database tables.
The integration tests are performed on the service classes which tests the underlying layers and connects to a H2 database that resets on each test.
The mock tests are performed on the Controllers and therefore mock the service classes so that the endpoints can be tested separately.
This provides wide coverage throughout classes:
- Navigate to the
backend
directory
cd backend
- Run tests
./mvnw clean test
Frontend test are performed using two different test models:
- Unit tests using Vitest
- E2E test using cypress
In out app the frontend unit test are testing the basic functionalities of the specific components. This can be functionalities such as button click, correct input expected or database mocking and testing api calls. The e2e test are used to further test the functionalites of the specific page.
This provides wide coverage throughout classes:
-
Navigate to the
frontend
directory -
Run tests
npm run test:unit
- Run e2e tests:
npm run test:e2e
- run vitest with coverage:
vitest --coverage
This is the code block that represents the continuous integration run on each pipline at merge and push:
image: maven:eclipse-temurin
stages:
- build
- test
- deploy
build-backend-job:
stage: build
script:
- cd backend
- mvn install -B -DskipTests # Skip tests during build phase
build-frontend-job:
image: node:16
stage: build
script:
- cd frontend
- npm install
- npm run build
unit-test-backend-job:
stage: test
script:
- cd backend
- mvn clean test
unit-test-frontend-job:
image: node:16
stage: test
script:
- cd frontend
- npm install
- npm run test:unit
e2e-test-frontend-job:
image: cypress/base:16.13.0 # Use the Cypress base image with Node 16.13.0
stage: test
script:
- cd frontend
- npm install
- npx vite --port 5173 & # Add the --root option here
- sleep 10
- npx cypress run --e2e
This block both builds and tests the backend and frontend part of the application through compilation, unit-tests, integration tests and end-to-end tests
The javadoc is also deployed to gitlab pages on merge to development using this pipline code block:
pages:
stage: deploy
script:
- mkdir .public
- cp -r javadoc/* .public
- mv .public public
artifacts:
paths:
- public
only:
- development