Skip to content

Instantly share code, notes, and snippets.

@SaahilClaypool
Created April 25, 2021 01:59
Show Gist options
  • Save SaahilClaypool/d0087f3a9f61df47279c5f90d1308183 to your computer and use it in GitHub Desktop.
Save SaahilClaypool/d0087f3a9f61df47279c5f90d1308183 to your computer and use it in GitHub Desktop.
In-project unit tests c#
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<!-- This stops c# from creating th stub main automatically -->
<!-- https://andrewlock.net/fixing-the-error-program-has-more-than-one-entry-point-defined-for-console-apps-containing-xunit-tests/ -->
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<Compile Remove="**\*.Test.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
@SaahilClaypool
Copy link
Author

using System;
using Xunit;

namespace MyFirstUnitTests
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
                Assert.Equal(4, 2 + 2);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment