Skip to content

Commit 4a639e4

Browse files
committed
Added TestFrameworkSamples/TUnitProject
1 parent 3971094 commit 4a639e4

File tree

7 files changed

+116
-1
lines changed

7 files changed

+116
-1
lines changed

TestFrameworkSamples/NUnitProject/BasicTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Security.Cryptography;
21
using NUnit.Framework;
32

43
namespace NUnitProject;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace TUnitProject;
2+
3+
public class BasicTest
4+
{
5+
[Test]
6+
public void TestMethod1()
7+
{
8+
Console.WriteLine("This is a basic test");
9+
}
10+
11+
[Test]
12+
[DisplayName("Test Method 2")]
13+
public void TestMethod2()
14+
{
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace TUnitProject;
2+
3+
public class DataDrivenTest
4+
{
5+
[Test]
6+
[Arguments("foo", 42)]
7+
[Arguments("bar", 43)]
8+
[Arguments("baz", 44)]
9+
public void DataDriven1(string strParam, int intParam)
10+
{
11+
12+
}
13+
14+
[Test]
15+
[DisplayName("Data Driven 2")]
16+
[Arguments("foo", 42)]
17+
[Arguments("bar", 43)]
18+
[Arguments("baz", 44)]
19+
public void DataDriven2(string strParam, int intParam)
20+
{
21+
22+
}
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace TUnitProject;
2+
3+
public class DynamicDataDrivenTest
4+
{
5+
[Test]
6+
[MethodDataSource(nameof(DynamicDataDriven1DataSource))]
7+
public void DynamicDataDriven1(string strParam, int intParam)
8+
{
9+
10+
}
11+
12+
public static IEnumerable<(string strParam, int intParam)> DynamicDataDriven1DataSource()
13+
{
14+
yield return ("foo", 42);
15+
yield return ("bar", 43);
16+
yield return ("baz", 44);
17+
}
18+
19+
[Test]
20+
[DynamicDataDriven2DataGenerator]
21+
public void DynamicDataDriven2(string strParam, int intParam)
22+
{
23+
24+
}
25+
26+
public class DynamicDataDriven2DataGenerator : DataSourceGeneratorAttribute<string, int>
27+
{
28+
public override IEnumerable<Func<(string, int)>> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata)
29+
{
30+
yield return () => ("foo", 42);
31+
yield return () => ("bar", 43);
32+
yield return () => ("baz", 44);
33+
}
34+
}
35+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Here you could define global logic that would affect all tests
2+
3+
// You can use attributes at the assembly level to apply to all tests in the assembly
4+
[assembly: Retry(3)]
5+
[assembly: System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
6+
7+
namespace TUnitProject;
8+
9+
public class GlobalHooks
10+
{
11+
[Before(TestSession)]
12+
public static void SetUp()
13+
{
14+
Console.WriteLine(@"Or you can define methods that do stuff before...");
15+
}
16+
17+
[After(TestSession)]
18+
public static void CleanUp()
19+
{
20+
Console.WriteLine(@"...and after!");
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<OutputType>Exe</OutputType>
7+
<TargetFramework>net8.0</TargetFramework>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="TUnit" Version="0.25.21" />
12+
</ItemGroup>
13+
14+
</Project>

TestFrameworkSamples/TestFrameworkSamples.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MsTestProject", "MsTestProj
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NUnitProject", "NUnitProject\NUnitProject.csproj", "{41ED04DF-8254-40B5-AE1E-1AC6F6A24192}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TUnitProject", "TUnitProject\TUnitProject.csproj", "{1494E1B0-AEF2-5A26-2A0B-A036EBB2D1E8}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
2729
{41ED04DF-8254-40B5-AE1E-1AC6F6A24192}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{41ED04DF-8254-40B5-AE1E-1AC6F6A24192}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{41ED04DF-8254-40B5-AE1E-1AC6F6A24192}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{1494E1B0-AEF2-5A26-2A0B-A036EBB2D1E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{1494E1B0-AEF2-5A26-2A0B-A036EBB2D1E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{1494E1B0-AEF2-5A26-2A0B-A036EBB2D1E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{1494E1B0-AEF2-5A26-2A0B-A036EBB2D1E8}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)