Skip to content

Commit

Permalink
Backend testing updates (#75)
Browse files Browse the repository at this point in the history
* got backend coverage

* add tests to mstests

* readme testing updates

* Attempt at fixing dotnet tests

* fixing dotnet testing

* Better fixes for github action

* add timelimit for docker container

* Update dotnet.yml to wait 10 seconds for docker to catch up

* removed incompatible os

* change readme

* Try to add backend coverage to codecov

* fix syntax

* fixed list in brackets

* new codecov attempr

* fix yml syntax errors

* Fix file names

* add tests for atmos controller

* fixed family and properties tests

* Add unhappy initial conditions path

* Update dotnet.yml

* Add coverage and add backend to codecov

* Fix mysql loading for codecov

* update code coverage

* fix file names

* Try moving manual code cov file

* Reformat coverage files

* fix workflow syntax

* Rename files to get seen by codecov

* Add more unhappy path tests

* Manually add coverage for backend

* Manually add test coverage and remove workflow job
  • Loading branch information
SydZero authored Nov 27, 2024
1 parent 1d5eb78 commit 7ce23c5
Show file tree
Hide file tree
Showing 55 changed files with 131,064 additions and 974 deletions.
46 changes: 7 additions & 39 deletions .github/workflows/codecov_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ on:
- main

jobs:
Frontend-Codecov-Publishing:
Codecov-Publishing:
runs-on: ubuntu-latest

steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v2

# Setup .NET environment
# Setup Node environment
- name: Setup Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -33,49 +33,17 @@ jobs:
run: npm run build
working-directory: ./frontend

# Step 5: Run tests and collect code coverage
# Step 5: Run tests and collect code coverage
- name: Test and calculate coverage
run: npm run test:coverage
working-directory: ./frontend


# Step 6: Upload the code coverage report to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v4.2.0
with:
token: ${{ secrets.CODECOV_TOKEN }} # Add the Codecov token in the GitHub secrets
files: ./frontend/coverage/lcov.info # Ensure the correct path for the coverage file
flags: vite-tests
token: ${{ secrets.CODECOV_TOKEN }}
# files: ./frontend/coverage/lcov.info, ./ManualCoverageBackend.cobertura.xml
flags: frontend
fail_ci_if_error: true
# # Setup .NET environment
# - name: Setup .NET
# uses: actions/setup-dotnet@v3
# with:
# context: ./backend
# dotnet-version: 6.0.x # Use the version your project requires

# # Restore dependencies
# - name: Restore dependencies
# run: dotnet restore ./backend

# # Build the project
# - name: Build
# run: dotnet build ./backend --no-restore

# # Step 5: Run tests and collect code coverage
# - name: Test and calculate coverage
# run: |
# dotnet test ./backend --no-build --verbosity normal --logger "console;verbosity=detailed" \
# /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
# /p:CoverletOutput=./TestResults/coverage.cobertura.xml


# # Step 6: Upload the code coverage report to Codecov
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
# with:
# context: ./backend
# token: ${{ secrets.CODECOV_TOKEN }} # Add the Codecov token in the GitHub secrets
# files: ./TestResults/coverage.opencover.xml # Ensure the correct path for the coverage file
# flags: unittests
# fail_ci_if_error: true
70 changes: 44 additions & 26 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,48 @@ on:

jobs:
build:
continue-on-error: true
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest # does not run on other platforms
steps:
# Check out the code from the repository
- name: Checkout repository
uses: actions/checkout@v3

# Set up .NET with version 6.0.x
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

# Restore the dependencies of the .NET project
- name: Restore dependencies
run: dotnet restore ./backend

# Build the project
- name: Build
run: dotnet build ./backend --no-restore

# Run tests
- name: Test
run: dotnet test ./backend --no-build --verbosity normal
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore ./backend

- name: Build
run: dotnet build ./backend --no-restore

- name: Start database container
run: docker compose up -d mysql

- name: List running containers
run: docker ps -a

- name: Wait for database to be ready
run: |
for i in {1..30}; do
if docker exec $(docker ps -q --filter "name=mysql") mysqladmin ping -h"localhost" --silent; then
echo "Database is ready!"
sleep 10
exit 0
fi
echo "Waiting for database connection..."
sleep 2
done
echo "Database failed to start within the expected time."
exit 1
- name: Test
run: dotnet test ./backend --collect "Code Coverage;Format=Cobertura" --no-build --verbosity normal

- name: Stop and remove database container
run: docker compose down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ dist-ssr

node_modules/
/coverage
/coveragereport
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ and run the following commands:
brew install dotnet
```

## Running Chemistry Cafe with Docker Compose
### Running Chemistry Cafe with Docker Compose

You must have [Docker Desktop](https://www.docker.com/get-started) installed and running.
With Docker Desktop running, open a terminal window.
Expand All @@ -57,7 +57,7 @@ docker compose down
```
**Note:** To view changes, you must run the docker compose down and then run the project again.
## Running Chemistry Cafe Locally
### Running Chemistry Cafe Locally
You must open 3 terminals and run the following commands in each:
**Terminal 1**
Expand All @@ -76,6 +76,35 @@ npm run dev
```
docker compose up mysql
```
## Testing
### To test frontend
```
cd frontend
npm run test:coverage
```
If all tests past, the coverage report will generate in frontend/coverage/index.html
### To test backend
**Terminal 1**
```
docker compose up mysql
```
**Terminal 2**
```
cd backend
dotnet test --collect "Code Coverage;Format=cobertura" --settings ..\.runsettings
```
```
reportgenerator -reports:"TestResults\<guid>\<file-prefix>.cobertura.xml" -targetdir:coveragereport -reporttypes:Html -classfilters:-MySqlConnector.* -filefilters:-/_/src/MySqlConnector/*

```
If all tests past, the coverage report will generate in backend/coveragereport/index.html
# License
- [Apache 2.0](/LICENSE)
Expand Down
Loading

0 comments on commit 7ce23c5

Please sign in to comment.