Skip to content

Commit

Permalink
Test unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelayori committed Mar 18, 2024
1 parent babf582 commit 7a5942c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 25 deletions.
94 changes: 82 additions & 12 deletions .github/workflows/unit-tests-push.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,104 @@
name: Unit tests
name: Continuous Integration

on:
push:
branches:
- master
- unit-tests
- develop
pull_request:
types: [opened, synchronize, reopened]

jobs:
unit-tests:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:latest
image: mysql:8.3
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_database
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@v1
- name: Set up JDK
uses: actions/setup-java@v1
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
- name: Add exec permission to mvnw
run: chmod +x mvnw
- name: Build and test
run: |
./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
- name: Cache Maven
uses: actions/cache@v2
with:
path: |
~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run unit tests
run: ./mvnw test -Dgroups="unit"
env:
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root

integration-tests:
needs: unit-tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.3
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_database
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
- name: Set up Chrome
uses: browser-actions/setup-chrome@latest
- name: Set up ChromeDriver
uses: browser-actions/setup-chromedriver@latest
- name: Cache Maven
uses: actions/cache@v2
with:
path: |
~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run integration tests with Selenium
run: ./mvnw test -Dgroups="integration"
env:
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root

sonarcloud-analysis:
needs: unit-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: SonarCloud analysis
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
13 changes: 0 additions & 13 deletions src/test/java/com/uniovi/WiqEs04bApplicationTests.java

This file was deleted.

17 changes: 17 additions & 0 deletions src/test/java/com/uniovi/Wiq_IntegrationTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.uniovi;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;

@SpringBootTest
@Tag("integration")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
class Wiq_IntegrationTests {

@Test
void contextLoads() {
}

}
17 changes: 17 additions & 0 deletions src/test/java/com/uniovi/Wiq_UnitTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.uniovi;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;

@SpringBootTest
@Tag("unit")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
class Wiq_UnitTests {

@Test
void contextLoads() {
}

}

0 comments on commit 7a5942c

Please sign in to comment.