Skip to content

Instantly share code, notes, and snippets.

@thomaslevesque
Last active November 3, 2022 07:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaslevesque/372b8cff3661c3be1d3fb5181ce5d89c to your computer and use it in GitHub Desktop.
Save thomaslevesque/372b8cff3661c3be1d3fb5181ce5d89c to your computer and use it in GitHub Desktop.
Tests in same project
bin/
obj/
.vs/
.idea/
.vscode/
*.user
namespace TestsInSameProject;
class Calculator
{
public int Add(int x, int y) => x + y;
}
using Xunit;
namespace TestsInSameProject;
public class CalculatorTests
{
[Theory]
[InlineData(1, 2, 3)]
[InlineData(1, 0, 1)]
[InlineData(0, 0, 0)]
[InlineData(1, -2, -1)]
public void Add_Returns_Sum_Of_Arguments(int x, int y, int expected)
{
var calculator = new Calculator();
var actual = calculator.Add(x, y);
Assert.Equal(expected, actual);
}
}
{
"sdk": {
"version": "6.0.402"
}
}
using TestsInSameProject;
if (args.Length < 2)
{
Console.Error.WriteLine("Missing arguments");
return 1;
}
int x = int.Parse(args[0]);
int y = int.Parse(args[1]);
var calculator = new Calculator();
int result = calculator.Add(x, y);
Console.WriteLine(result);
return 0;
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup Condition="$(StripTests) != 'true'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="$(StripTests) == 'true'">
<Compile Remove="**/*Tests.cs" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment