Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fa51910
Created Basic F# template
licon4812 May 15, 2025
45d17cc
updated TUnit.Fsharp template
licon4812 May 16, 2025
410afef
Updated TUnit.FSharp template
licon4812 May 16, 2025
f19c621
Updated TUnit.FSharp template.json
licon4812 May 16, 2025
97e425d
Created basic VB template
licon4812 May 16, 2025
8fb9e61
updated VB templates
licon4812 May 16, 2025
e8748cb
Update Tests.vb
licon4812 May 16, 2025
ee7278f
Added GlobalSetup.vb to VB TUnit template
licon4812 May 16, 2025
dee36c2
Updated C# TUnit Template
licon4812 May 16, 2025
97c46e8
Merge remote-tracking branch 'upstream/main' into f#-vb-templates
licon4812 May 17, 2025
a648c03
updated basic templates to TUnit 0.20.4
licon4812 May 17, 2025
0c352e7
Tests in F# template to use TUnit.Assertions.F#
licon4812 May 17, 2025
38d89df
Update fsharp.md
licon4812 May 17, 2025
81ad9b9
Merge remote-tracking branch 'upstream/main' into f#-vb-templates
licon4812 May 18, 2025
be6eb64
Merge remote-tracking branch 'upstream/main' into f#-vb-templates
licon4812 May 18, 2025
fe212ae
Updated TUnit version in Basic Templates
licon4812 May 18, 2025
f79b0a1
Updated tests in VB and F# template using ClassDataSource
licon4812 May 18, 2025
3d43919
updated vb and f# tests 3
licon4812 May 18, 2025
f570e9e
Merge remote-tracking branch 'upstream/main' into f#-vb-templates
licon4812 May 19, 2025
4db6523
updated TUnit version in vb and f# templates
licon4812 May 19, 2025
7f19f92
Finished f# template
licon4812 May 19, 2025
be50a1d
updated TUnit c# template
licon4812 May 19, 2025
f023f9d
Added Template tests for VB and F#
licon4812 May 19, 2025
d0b2988
Update AspNetTemplateTests.cs
licon4812 May 20, 2025
7754306
updated template tests
licon4812 May 20, 2025
6631a24
Added TUnit.Assertions.FSharp
licon4812 May 20, 2025
03accf4
Merge branch 'main' into f#-vb-templates
thomhurst May 20, 2025
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
2 changes: 1 addition & 1 deletion TUnit.Templates.Tests/AspNetTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class AspNetTemplateTests : TemplateTestBase
{
protected override string TemplateShortName => "TUnit.AspNet";
protected override string TemplateShortName { get; set; } = "TUnit.AspNet";

[Test]
public async Task InstantiationTest()
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Templates.Tests/AspireStarterTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class AspireStarterTemplateTests : TemplateTestBase
{
protected override string TemplateShortName => "TUnit.Aspire.Starter";
protected override string TemplateShortName { get; set; } = "TUnit.Aspire.Starter";

[Test]
public async Task InstantiationTest()
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Templates.Tests/AspireTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class AspireTemplateTests:TemplateTestBase
{
protected override string TemplateShortName => "TUnit.Aspire.Test";
protected override string TemplateShortName { get; set; } = "TUnit.Aspire.Test";

[Test]
public async Task InstantiationTest()
Expand Down
16 changes: 15 additions & 1 deletion TUnit.Templates.Tests/BasicTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

public class BasicTemplateTests : TemplateTestBase
{
protected override string TemplateShortName => "TUnit";
protected override string TemplateShortName { get; set; } = "TUnit";

[Test]
public async Task InstantiationTest()
{
await Engine.Execute(Options).ConfigureAwait(false);
}

[Test]
public async Task InstantiationTestWithFSharp()
{
TemplateShortName = "TUnit.FSharp";

Check warning on line 16 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Test methods should not assign instance data

Check warning on line 16 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Test methods should not assign instance data

Check warning on line 16 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (ubuntu-latest)

Test methods should not assign instance data

Check warning on line 16 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (ubuntu-latest)

Test methods should not assign instance data

Check warning on line 16 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (macos-latest)

Test methods should not assign instance data

Check warning on line 16 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (macos-latest)

Test methods should not assign instance data
await Engine.Execute(Options).ConfigureAwait(false);
}

[Test]
public async Task InstantiationTestWithVB()
{
TemplateShortName = "TUnit.VB";

Check warning on line 23 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Test methods should not assign instance data

Check warning on line 23 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Test methods should not assign instance data

Check warning on line 23 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (ubuntu-latest)

Test methods should not assign instance data

Check warning on line 23 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (ubuntu-latest)

Test methods should not assign instance data

Check warning on line 23 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (macos-latest)

Test methods should not assign instance data

Check warning on line 23 in TUnit.Templates.Tests/BasicTemplateTests.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (macos-latest)

Test methods should not assign instance data
await Engine.Execute(Options).ConfigureAwait(false);
}
}
2 changes: 1 addition & 1 deletion TUnit.Templates.Tests/PlaywriteTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class PlaywriteTemplateTests : TemplateTestBase
{
protected override string TemplateShortName => "TUnit.Playwright";
protected override string TemplateShortName { get; set; } = "TUnit.Playwright";

[Test]
public async Task InstantiationTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace TUnit.FSharp

open System
open System.Threading.Tasks
open TUnit.Core.Interfaces

type DataClass() =
interface IAsyncInitializer with
member _.InitializeAsync() : Task =
Console.Out.WriteLineAsync("Classes can be injected into tests, and they can perform some initialisation logic such as starting an in-memory server or a test container.")

interface IAsyncDisposable with
member _.DisposeAsync() : ValueTask =
ValueTask(Console.Out.WriteLineAsync("And when the class is finished with, we can clean up any resources."))

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TUnit.FSharp.Data

open System
open System.Collections.Generic
open TUnit.Core

type DataGenerator() =
inherit DataSourceGeneratorAttribute<int, int, int>()

override _.GenerateDataSources(_: DataGeneratorMetadata) : IEnumerable<Func<struct (int * int * int)>> =
seq {
yield Func<struct (int * int * int)>(fun () -> struct (1, 1, 2))
yield Func<struct (int * int * int)>(fun () -> struct (1, 2, 3))
yield Func<struct (int * int * int)>(fun () -> struct (4, 5, 9))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace TUnit.FSharp

open System
open Microsoft.Extensions.DependencyInjection
open TUnit.Core.Interfaces
open TUnit.Core

type DependencyInjectionClassConstructor() =
let serviceProvider =
ServiceCollection()
// Register your dependencies here, e.g.:
.AddTransient<DataClass>()
.BuildServiceProvider()

interface IClassConstructor with
member _.Create(typ: Type, _: ClassConstructorMetadata) : obj =
Console.WriteLine("You can also control how your test classes are new'd up, giving you lots of power and the ability to utilise tools such as dependency injection")
ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, typ)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace TUnit.FSharp

// Here you could define global logic that would affect all tests

// You can use attributes at the assembly level to apply to all tests in the assembly
open System
open System.Diagnostics.CodeAnalysis
open TUnit.Core

[<assembly: Retry(3)>]
[<assembly: ExcludeFromCodeCoverage>]
do ()

type GlobalHooks() =
[<Before(HookType.TestSession)>]
static member SetUp() =
Console.WriteLine("Or you can define methods that do stuff before...")

[<After(HookType.TestSession)>]
static member CleanUp() =
Console.WriteLine("...and after!")

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
<PackageReference Include="TUnit" Version="0.21.1" />
<PackageReference Include="TUnit.Assertions.FSharp" Version="0.21.1" />
</ItemGroup>

<ItemGroup>
<Compile Include="Data\DataClass.fs" />
<Compile Include="Data\DataGenerator.fs" />
<Compile Include="Data\DependencyInjectionClassConstructor.fs" />
<Compile Include="GlobalSetup.fs" />
<Compile Include="Tests.fs" />
<Compile Include="Tests2.fs" />
<Compile Include="Tests3.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace TUnit.FSharp

open System
open System.Collections.Generic
open System.Threading.Tasks
open TUnit.FSharp.Data
open TUnit
open TUnit.Core
open TUnit.Assertions
open TUnit.Assertions.Extensions
open TUnit.Assertions.FSharp.Operations

type Tests() =

[<Test>]
member _.Basic() =
Console.WriteLine("This is a basic test")

[<Test>]
[<Arguments(1, 2, 3)>]
[<Arguments(2, 3, 5)>]
member _.DataDrivenArguments(a: int, b: int, c: int) =
async {
Console.WriteLine("This one can accept arguments from an attribute")
let result = a + b
do! check(Assert.That(result).IsEqualTo(c))
}


[<Test>]
[<MethodDataSource("DataSource")>]
member _.MethodDataSource(a: int, b: int, c: int) =
async {
Console.WriteLine("This one can accept arguments from a method")
let result = a + b
do! check(Assert.That(result).IsEqualTo(c))
}

[<Test>]
[<ClassDataSource(typeof<DataClass>)>]
[<ClassDataSource(typeof<DataClass>, Shared = SharedType.PerClass)>]
[<ClassDataSource(typeof<DataClass>, Shared = SharedType.PerAssembly)>]
[<ClassDataSource(typeof<DataClass>, Shared = SharedType.PerTestSession)>]
member _.ClassDataSource(dataClass: DataClass) =
Console.WriteLine("This test can accept a class, which can also be pre-initialised before being injected in")
Console.WriteLine("These can also be shared among other tests, or new'd up each time, by using the `Shared` property on the attribute")

[<Test>]
[<DataGenerator>]
member _.CustomDataGenerator(a: int, b: int, c: int) =
async {
Console.WriteLine("You can even define your own custom data generators")
let result = a + b
do! check(Assert.That(result).IsEqualTo(c))
}

static member DataSource() : IEnumerable<struct (int * int * int)> =
seq {
yield struct (1, 1, 2)
yield struct (2, 1, 3)
yield struct (3, 1, 4)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace TUnit.FSharp

open System
open TUnit.Core

[<Arguments("Hello")>]
[<Arguments("World")>]
type MoreTests(title: string) =

[<Test>]
member _.ClassLevelDataRow() =
Console.WriteLine(title)
Console.WriteLine("Did I forget that data injection works on classes too?")

[<ClassDataSource(typeof<DataClass>, Shared = SharedType.PerTestSession)>]
member val DataClass: DataClass = Unchecked.defaultof<_> with get, set

[<Test>]
[<MatrixDataSource>]
member _.Matrices
(
[<Matrix(1, 2, 3)>] a: int,
[<Matrix(true, false)>] b: bool,
[<Matrix("A", "B", "C")>] c: string
) =
Console.WriteLine("A new test will be created for each data row, whether it's on the class or method level!")
Console.WriteLine("Oh and this is a matrix test. That means all combinations of inputs are attempted.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace TUnit.FSharp

open System
open TUnit.Core

[<ClassDataSource(typeof<DataClass>)>]
[<ClassConstructor(typeof<DependencyInjectionClassConstructor>)>]
type AndEvenMoreTests(dataClass: DataClass) =

[<Test>]
member _.HaveFun() =
Console.WriteLine(dataClass)
Console.WriteLine("For more information, check out the documentation")
Console.WriteLine("https://tunit.dev/")

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Imports System
Imports System.Threading.Tasks
Imports TUnit.Core.Interfaces

Public Class DataClass
Implements IAsyncInitializer, IAsyncDisposable

Public Function InitializeAsync() As Task Implements IAsyncInitializer.InitializeAsync
Return Console.Out.WriteLineAsync("Classes can be injected into tests, and they can perform some initialisation logic such as starting an in-memory server or a test container.")
End Function

Public Function DisposeAsync() As ValueTask Implements IAsyncDisposable.DisposeAsync
Return New ValueTask(DisposeAsyncTask())
End Function

Private Async Function DisposeAsyncTask() As Task
Await Console.Out.WriteLineAsync("And when the class is finished with, we can clean up any resources.")
End Function
End Class
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Imports System
Imports System.Collections.Generic
Imports TUnit.Core

Namespace Data
Public Class DataGenerator
Inherits DataSourceGeneratorAttribute(Of Integer, Integer, Integer)

Public Overrides Iterator Function GenerateDataSources(dataGeneratorMetadata As DataGeneratorMetadata) As IEnumerable(Of Func(Of (Integer, Integer, Integer)))
Yield Function() (1, 1, 2)
Yield Function() (1, 2, 3)
Yield Function() (4, 5, 9)
End Function

End Class
End Namespace

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Imports System
Imports TUnit.Core
Imports TUnit.Core.Interfaces
Public Class DependencyInjectionClassConstructor
Implements IClassConstructor

Public Function Create(Of T As Class)(classConstructorMetadata As ClassConstructorMetadata) As T
Console.WriteLine("You can also control how your test classes are new'd up, giving you lots of power and the ability to utilise tools such as dependency injection")

If GetType(T) Is GetType(AndEvenMoreTests) Then
Return CType(DirectCast(New AndEvenMoreTests(New DataClass()), Object), T)
End If

Throw New NotImplementedException()
End Function

' Explicit interface implementation for IClassConstructor.Create(Type, ClassConstructorMetadata)
Private Function IClassConstructor_Create(type As Type, classConstructorMetadata As ClassConstructorMetadata) As Object Implements IClassConstructor.Create
If type Is GetType(AndEvenMoreTests) Then
Return New AndEvenMoreTests(New DataClass())
End If

Throw New NotImplementedException()
End Function

End Class
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
' Here you could define global logic that would affect all tests

' You can use attributes at the assembly level to apply to all tests in the assembly
Imports TUnit.Core

<Assembly: Retry(3)>
<Assembly: CodeAnalysis.ExcludeFromCodeCoverage>

Public Class GlobalHooks

<Before(HookType.TestSession)>
Public Shared Sub SetUp()
Console.WriteLine("Or you can define methods that do stuff before...")
End Sub

<After(HookType.TestSession)>
Public Shared Sub CleanUp()
Console.WriteLine("...and after!")
End Sub

End Class
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TUnit" Version="0.21.1" />
</ItemGroup>
</Project>
Loading
Loading