Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Tests

on:
push:
branches: [ "main" ]
paths:
- 'backend/**'
- '.github/workflows/test.yml'
pull_request:
branches: [ "main" ]
paths:
- 'backend/**'
- '.github/workflows/test.yml'

jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven

- name: Run unit tests
working-directory: backend
run: mvn -B test -Dtest='!*IT,!*IntegrationTest' --fail-at-end

- name: Upload unit test results
if: always()
uses: actions/upload-artifact@v4
with:
name: unit-test-results
path: backend/target/surefire-reports/
retention-days: 7

integration-tests:
Comment thread Fixed
name: Integration Tests
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16
env:
POSTGRES_DB: autonow_test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven

- name: Run integration tests
working-directory: backend
env:
SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/autonow_test
SPRING_DATASOURCE_USERNAME: test
SPRING_DATASOURCE_PASSWORD: test
run: mvn -B test -Dtest='*IT,*IntegrationTest' --fail-at-end

- name: Upload integration test results
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-results
path: backend/target/surefire-reports/
retention-days: 7

test-summary:
Comment thread Fixed
name: Test Summary
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests]
if: always()

steps:
- name: Check test results
run: |
if [[ "${{ needs.unit-tests.result }}" == "failure" || "${{ needs.integration-tests.result }}" == "failure" ]]; then
echo "Tests failed!"
exit 1
fi
echo "All tests passed!"
Comment thread Fixed
5 changes: 5 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions backend/src/test/java/com/angel/autonow/ExampleControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.angel.autonow;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ExampleControllerTest {

@Test
void exampleEndpoint() {
String result = new ExampleController().exampleEndpoint();
assertEquals("hello", result);
}
}

This file was deleted.

Loading