Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
69 changes: 69 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Tests

permissions:
contents: read

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

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
run: mvn -B test -Dtest='*IT,*IntegrationTest' -Dspring.profiles.active=test --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
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
30 changes: 30 additions & 0 deletions backend/src/test/java/com/angel/autonow/ExampleControllerIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.angel.autonow;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
class ExampleControllerIT {

@Autowired
private MockMvc mockMvc;

@Test
@DisplayName("GET /api/test should return hello")
void shouldReturnHello() throws Exception {
mockMvc.perform(get("/api/test"))
.andExpect(status().isOk())
.andExpect(content().string("hello"));
}
}
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