Skip to content

Commit

Permalink
Add Unit Tests and Improve Code Coverage (#47)
Browse files Browse the repository at this point in the history
* Update Program.cs

* Create Testable.cs

* Update Program.cs

* Update POCTemplate.Tests.csproj

* Update UnitTest1.cs

* Create TestableTests.cs
  • Loading branch information
guibranco authored Aug 4, 2024
1 parent 5811295 commit e91de5d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Src/POCTemplate/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace POCTemplate;
using System.Diagnostics.CodeAnalysis;

namespace POCTemplate;

[ExcludeFromCodeCoverage]
internal static class Program
{
public static void Main()
static void Main(string[] args)
{
// This is a placeholder for the main entry point of the application.
Console.WriteLine("Hello, World!");
}
}
9 changes: 9 additions & 0 deletions Src/POCTemplate/Testable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace POCTemplate;

public class Testable
{
public bool TestableMethod()
{
return true;
}
}
6 changes: 3 additions & 3 deletions Tests/POCTemplate.Tests/POCTemplate.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
Expand All @@ -24,11 +24,11 @@
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
<ProjectReference Include="..\..\Src\POCTemplate\POCTemplate.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\POCTemplate\POCTemplate.csproj" />
<Using Include="Xunit" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions Tests/POCTemplate.Tests/TestableTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentAssertions;

namespace POCTemplate.Tests;

public class TestableTests
{
[Fact]
public void TestableMethod_StateUnderTest_ExpectedBehavior()
{
// Arrange
var testable = new Testable();

// Act
var result = testable.TestableMethod();

// Assert
result.Should().BeTrue();
}
}
14 changes: 13 additions & 1 deletion Tests/POCTemplate.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ namespace POCTemplate.Tests;

public class UnitTest1
{
/// <summary>
/// Tests the functionality of a specific feature or method.
/// </summary>
/// <remarks>
/// This test method, named <c>Test1</c>, is designed to verify that a boolean value evaluates to the expected result.
/// It uses the Arrange-Act-Assert pattern, which is a common practice in unit testing.
/// In the Arrange phase, the expected value is set to <c>true</c>.
/// In the Act phase, a boolean variable <c>value</c> is assigned the value <c>true</c> as well.
/// Finally, in the Assert phase, the test checks if <c>value</c> matches the expected value using Fluent Assertions.
/// This ensures that the functionality being tested behaves as intended.
/// </remarks>
[Fact]
public void Test1()
{
// Arrange
const bool expected = true;

// Act
var value = true;

// Assert
expected.Should().BeTrue();
value.Should().Be(expected);
}
}

0 comments on commit e91de5d

Please sign in to comment.