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
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.100

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotnet 7 is already EOL

dotnet-version: 8.0.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -42,7 +42,7 @@ jobs:
- name: Start session
run: 'launchable record session --build "$GITHUB_RUN_ID" > test_session.txt'
- name: Run test
run: dotnet test --logger:"nunit;LogFilePath=test-result.xml"
run: dotnet test --logger:"nunit;LogFilePath=test-result.xml" --logger:"junit;LogFilePath=junit-result.xml"
- name: Record test results
run: launchable record test --session "$(cat test_session.txt)" dotnet test-result.xml
if: always()
6 changes: 6 additions & 0 deletions dotnet/AddCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace rocket_car_dotnet;

public class AddCalculator
{
public int Add(int a, int b) => a + b;
}
21 changes: 21 additions & 0 deletions dotnet/AddCalculatorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace rocket_car_dotnet;

public class AddCalculatorTest
{
private readonly AddCalculator _calculator = new();

[Test]
public void TestAdd()
{
Assert.That(_calculator.Add(2, 3), Is.EqualTo(5));
Assert.That(_calculator.Add(-1, 1), Is.EqualTo(0));
Assert.That(_calculator.Add(0, 0), Is.EqualTo(0));
}

// Intentionally failing test to verify failure reporting in test reports
[Test]
public void TestAddFailing()
{
Assert.That(_calculator.Add(2, 3), Is.EqualTo(999));
}
}
16 changes: 16 additions & 0 deletions dotnet/Calculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace rocket_car_dotnet;

public class Calculator
{
private readonly AddCalculator _add = new();
private readonly SubtractCalculator _subtract = new();
private readonly MultiplyCalculator _multiply = new();
private readonly DivideCalculator _divide = new();
private readonly PowerCalculator _power = new();

public int Add(int a, int b) => _add.Add(a, b);
public int Subtract(int a, int b) => _subtract.Subtract(a, b);
public int Multiply(int a, int b) => _multiply.Multiply(a, b);
public double Divide(double a, double b) => _divide.Divide(a, b);
public double Power(double base_, double exponent) => _power.Power(base_, exponent);
}
11 changes: 11 additions & 0 deletions dotnet/DivideCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace rocket_car_dotnet;

public class DivideCalculator
{
public double Divide(double a, double b)
{
if (b == 0)
throw new ArgumentException("Cannot divide by zero");
return a / b;
}
}
27 changes: 27 additions & 0 deletions dotnet/DivideCalculatorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace rocket_car_dotnet;

public class DivideCalculatorTest
{
private readonly DivideCalculator _calculator = new();

[Test]
public void TestDivide()
{
Assert.That(_calculator.Divide(10, 2), Is.EqualTo(5.0));
Assert.That(_calculator.Divide(9, 3), Is.EqualTo(3.0));
Assert.That(_calculator.Divide(-10, 2), Is.EqualTo(-5.0));
}

[Test]
public void TestDivideByZero()
{
Assert.Throws<ArgumentException>(() => _calculator.Divide(10, 0));
}

// Intentionally failing test to verify failure reporting in test reports

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failed due to this intentional failed test

[Test]
public void TestDivideFailing()
{
Assert.That(_calculator.Divide(10, 2), Is.EqualTo(99.0));
}
}
18 changes: 0 additions & 18 deletions dotnet/Example.cs

This file was deleted.

37 changes: 0 additions & 37 deletions dotnet/ExampleTest.cs

This file was deleted.

6 changes: 6 additions & 0 deletions dotnet/MultiplyCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace rocket_car_dotnet;

public class MultiplyCalculator
{
public int Multiply(int a, int b) => a * b;
}
14 changes: 14 additions & 0 deletions dotnet/MultiplyCalculatorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace rocket_car_dotnet;

public class MultiplyCalculatorTest
{
private readonly MultiplyCalculator _calculator = new();

[Test]
public void TestMultiply()
{
Assert.That(_calculator.Multiply(2, 3), Is.EqualTo(6));
Assert.That(_calculator.Multiply(-2, 3), Is.EqualTo(-6));
Assert.That(_calculator.Multiply(0, 100), Is.EqualTo(0));
}
}
6 changes: 6 additions & 0 deletions dotnet/PowerCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace rocket_car_dotnet;

public class PowerCalculator
{
public double Power(double base_, double exponent) => Math.Pow(base_, exponent);
}
14 changes: 14 additions & 0 deletions dotnet/PowerCalculatorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace rocket_car_dotnet;

public class PowerCalculatorTest
{
private readonly PowerCalculator _calculator = new();

[Test]
public void TestPower()
{
Assert.That(_calculator.Power(2, 3), Is.EqualTo(8.0));
Assert.That(_calculator.Power(5, 2), Is.EqualTo(25.0));
Assert.That(_calculator.Power(10, 0), Is.EqualTo(1.0));
}
}
6 changes: 3 additions & 3 deletions dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Launchable recorded build test to workspace launchableinc/example with commits f
| ../ | ../ | 5fa3dc1aa3dc34589765898ec285e810b0bea422 |

# Run test
$ dotnet test --logger:"nunit;LogFilePath=test-result.xml"
$ dotnet test --logger:"nunit;LogFilePath=test-result.xml" --logger:"junit;LogFilePath=junit-result.xml"
...

Failed! - Failed: 3, Passed: 1, Skipped: 0, Total: 4, Duration: 24 ms - rocket-car-dotnet.dll (net7.0)
Failed! - Failed: 3, Passed: 1, Skipped: 0, Total: 4, Duration: 24 ms - rocket-car-dotnet.dll (net8.0)


$ launchable record tests --build ${BUILD_NAME} dotnet ./test-result.xml
Expand Down Expand Up @@ -57,7 +57,7 @@ FullyQualifiedName!=rocket_car_dotnet.ExampleTest.TestDiv
$ dotnet test --filter $(cat subset.txt)
...

Failed! - Failed: 2, Passed: 1, Skipped: 0, Total: 3, Duration: 25 ms - rocket-car-dotnet.dll (net7.0)
Failed! - Failed: 2, Passed: 1, Skipped: 0, Total: 3, Duration: 25 ms - rocket-car-dotnet.dll (net8.0)
```

## Split subset for parallel test runs
Expand Down
6 changes: 6 additions & 0 deletions dotnet/SubtractCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace rocket_car_dotnet;

public class SubtractCalculator
{
public int Subtract(int a, int b) => a - b;
}
14 changes: 14 additions & 0 deletions dotnet/SubtractCalculatorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace rocket_car_dotnet;

public class SubtractCalculatorTest
{
private readonly SubtractCalculator _calculator = new();

[Test]
public void TestSubtract()
{
Assert.That(_calculator.Subtract(5, 3), Is.EqualTo(2));
Assert.That(_calculator.Subtract(0, 5), Is.EqualTo(-5));
Assert.That(_calculator.Subtract(10, 10), Is.EqualTo(0));
}
}
15 changes: 8 additions & 7 deletions dotnet/rocket-car-dotnet.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>rocket_car_dotnet</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -10,12 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="NunitXml.TestLogger" Version="3.0.109" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="NunitXml.TestLogger" Version="8.0.0" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.134" />
</ItemGroup>

</Project>
Loading