From 93d3cdd9d4e218d0012af3af5d9c6557d428a305 Mon Sep 17 00:00:00 2001 From: raczu Date: Thu, 14 Mar 2024 20:37:53 +0100 Subject: [PATCH] ci: add workflow to unit tests code on each commit --- .github/workflows/unit-tests.yml | 34 +++++++++++++++++++++ Server/ReasnAPI/ReasnAPI.Tests/UnitTest1.cs | 21 ++----------- 2 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 00000000..a1319446 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,34 @@ +name: unit tests + +on: [push] + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Determine ReasnAPI solution filename + run: echo SOLUTION_FILE=$(realpath ./Server/ReasnAPI/ReasnAPI.sln) >> $GITHUB_ENV + + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Install dependencies + run: dotnet restore ${{ env.SOLUTION_FILE }} + + - name: Test with dotnet + run: | + dotnet test ${{ env.SOLUTION_FILE }} \ + --logger trx \ + --logger html \ + --results-directory "TestResults-${{ github.ref }}" + + - name: Upload dotnet test results + uses: actions/upload-artifact@v4 + with: + name: dotnet-results-${{ github.ref }} + path: TestResults-${{ github.ref }} + retention-days: 14 + if: ${{ always() }} \ No newline at end of file diff --git a/Server/ReasnAPI/ReasnAPI.Tests/UnitTest1.cs b/Server/ReasnAPI/ReasnAPI.Tests/UnitTest1.cs index 02d56ce1..46dac6f2 100644 --- a/Server/ReasnAPI/ReasnAPI.Tests/UnitTest1.cs +++ b/Server/ReasnAPI/ReasnAPI.Tests/UnitTest1.cs @@ -1,27 +1,12 @@ namespace ReasnAPI.Tests { [TestClass] - public class UnitTest1 : PageTest + public class UnitTest1 { [TestMethod] - public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage() + public void TestAdd() { - await Page.GotoAsync("https://playwright.dev"); - - // Expect a title "to contain" a substring. - await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); - - // create a locator - var getStarted = Page.Locator("text=Get Started"); - - // Expect an attribute "to be strictly equal" to the value. - await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro"); - - // Click the get started link. - await getStarted.ClickAsync(); - - // Expects the URL to contain intro. - await Expect(Page).ToHaveURLAsync(new Regex(".*intro")); + Assert.AreEqual(17, 17); } } }