Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
29f9d7a
added more f# tests
licon4812 May 21, 2025
4a44c66
Update Tests.fs
licon4812 May 21, 2025
b440fb2
Added CustomSkipAttribute to F# Example Test Project
licon4812 May 21, 2025
70cc7eb
reordered tests
licon4812 May 21, 2025
bc1a66d
Update Tests.fs
licon4812 May 21, 2025
487b66f
Updated FSharp Testing namespace
licon4812 May 21, 2025
141dbc6
Update Tests.fs
licon4812 May 21, 2025
880a6a6
Update Tests.fs
licon4812 May 21, 2025
1b4e6cb
Merge branch 'main' into f#-tests
licon4812 May 21, 2025
6667988
Merge remote-tracking branch 'upstream/main' into f#-tests
licon4812 May 21, 2025
0b35603
Update Tests.fs
licon4812 May 21, 2025
6e84232
Update Tests.fs
licon4812 May 21, 2025
ba26b75
Merge branch 'main' into f#-tests
licon4812 May 22, 2025
0def8b3
Merge branch 'main' into f#-tests
licon4812 May 22, 2025
d2d3f74
Added some more tests.
licon4812 May 22, 2025
a5687fb
more tests
licon4812 May 22, 2025
f99c22d
more tests
licon4812 May 22, 2025
5d2c17a
more tests
licon4812 May 22, 2025
d07b976
more tests
licon4812 May 22, 2025
6621332
more tests
licon4812 May 22, 2025
243842f
added fs file references to fsproj in TUnit.TestProject.FSharp.fsproj
licon4812 May 22, 2025
d1c62f0
Update DependencyInjectionClassConstructor.fs
licon4812 May 22, 2025
2ece1e0
Refactor UniqueBuilderContextsOnEnumerableDataGeneratorTests for clar…
licon4812 May 22, 2025
564b489
reorganised some tests in f# test project
licon4812 May 22, 2025
e029045
fixed some f# tests
licon4812 May 22, 2025
3d582e1
more tests
licon4812 May 23, 2025
d058616
small fixes
licon4812 May 23, 2025
cfcefe6
temp fix in F# tests project
licon4812 May 23, 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
Prev Previous commit
Next Next commit
fixed some f# tests
  • Loading branch information
licon4812 committed May 22, 2025
commit e029045d6caa29640b49c93f594b3016f80e1d37
31 changes: 17 additions & 14 deletions TUnit.TestProject.FSharp/AfterTestAttributeTests.fs
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
namespace TUnit.TestProject.FSharp

open System
open System.IO
open System.Threading.Tasks
open TUnit.Assertions
open TUnit.Assertions.Extensions
open TUnit.Core.Interfaces
open Polyfills
open TUnit.Core
open TUnit.Assertions.FSharp.Operations

// Equivalent of AfterTestAttributeTests.cs

type WriteFileAfterTestAttribute() =
inherit System.Attribute()
interface ITestEndEventReceiver with
member _.OnTestEnd(testContext: AfterTestContext) =
task {
Console.WriteLine("Writing file inside WriteFileAfterTestAttribute!")
do! FilePolyfill.WriteAllTextAsync(filename, "Foo!")
} :> Task
member _.Order = 0

type AfterTestAttributeTests() =
static let filename = sprintf "%s-AfterTestAttributeTests.txt" (Guid.NewGuid().ToString("N"))

[<Test>]
[<WriteFileAfterTest>]
member _.Test() : Task =
Assert.That(File.Exists(filename)).IsFalse()

and WriteFileAfterTestAttribute() =
inherit System.Attribute()
interface ITestEndEventReceiver with
member _.OnTestEnd(testContext: AfterTestContext) =
task {
Console.WriteLine("Writing file inside WriteFileAfterTestAttribute!")
do! FilePolyfill.WriteAllTextAsync(filename, "Foo!")
} :> Task
member _.Order = 0
member _.Test() =
async{
do! check(Assert.That<bool>(File.Exists(filename)).IsFalse())
}
3 changes: 2 additions & 1 deletion TUnit.TestProject.FSharp/ConflictingDependsOnTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ namespace TUnit.TestProject.FSharp

open System
open System.Threading.Tasks
open System.Diagnostics.CodeAnalysis
open TUnit.Core

[<UnconditionalSuppressMessage("Usage", "TUnit0033:Conflicting DependsOn attributes")>]
[<SuppressMessage("Usage", "TUnit0033:Conflicting DependsOn attributes")>]
type ConflictingDependsOnTests() =
[<Test>]
[<DependsOn("Test2")>]
Expand Down
7 changes: 1 addition & 6 deletions TUnit.TestProject.FSharp/DataDrivenTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ type DataDrivenTests() =
()

[<Test>]
[<Arguments([| 1; 2; 3 |])>]
member _.IntegerArray(values: int array) =
()

[<Test>]
[<Arguments(System.Int32.MaxValue)>]
[<Arguments(Int32.MaxValue)>]
member _.IntMaxValue(value: int) =
()
3 changes: 2 additions & 1 deletion TUnit.TestProject.FSharp/DeepNestedDependencyConflict.fs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace TUnit.TestProject.FSharp

open TUnit.Core
open System.Diagnostics.CodeAnalysis

// Equivalent of DeepNestedDependencyConflict.cs

[<UnconditionalSuppressMessage("Usage", "TUnit0033:Conflicting DependsOn attributes")>]
[<SuppressMessage("Usage", "TUnit0033:Conflicting DependsOn attributes")>]
type DeepNestedDependencyConflict() =
[<Test>]
[<DependsOn("Test2")>]
Expand Down
9 changes: 6 additions & 3 deletions TUnit.TestProject.FSharp/DynamicallyRegisteredTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open System.Threading.Tasks
open TUnit.Core
open TUnit.Core.Enums
open TUnit.Core.Interfaces
open TUnit.Engine.Extensions

type DynamicDataGenerator() =
inherit DataSourceGeneratorAttribute<int>()
Expand All @@ -33,10 +34,10 @@ type DynamicDataGenerator() =
raise (Exception())
if DynamicDataGenerator.IsReregisteredTest(testContext) then
() // Optionally suppress reporting
do! testContext.ReregisterTestWithArguments([|(Random()).Next()|],
dict [ "DynamicDataGeneratorRetry", box true ])
let retryDict = Dictionary<string, obj>()
retryDict.Add("DynamicDataGeneratorRetry", box true)
do! testContext.ReregisterTestWithArguments([|(Random()).Next()|], retryDict)
} |> ValueTask
member _.Order = 0

interface IEventReceiver with
member _.Order = 0
Expand All @@ -52,3 +53,5 @@ type DynamicallyRegisteredTests() =
raise (Exception($"Value {value} !"))




13 changes: 9 additions & 4 deletions TUnit.TestProject.FSharp/EnumerableDataSourceDrivenTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open System.Threading.Tasks
open TUnit.Assertions
open TUnit.Assertions.Extensions
open TUnit.Core
open TUnit.Assertions.FSharp.Operations

// F# equivalent of EnumerableDataSourceDrivenTests.cs

Expand All @@ -19,13 +20,17 @@ type ConcreteValue2() =
type EnumerableDataSourceDrivenTests() =
[<Test>]
[<MethodDataSource("SomeMethod")>]
member _.DataSource_Method(value: int) : Task =
Assert.That(value).IsEqualTo(1)
member _.DataSource_Method(value: int) =
async{
do! check(Assert.That(value).IsEqualTo(1))
}

[<Test>]
[<MethodDataSource("SomeMethod")>]
member _.DataSource_Method2(value: int) : Task =
Assert.That(value).IsEqualTo(1)
member _.DataSource_Method2(value: int) =
async{
do! check(Assert.That(value).IsEqualTo(1))
}

[<Test>]
[<MethodDataSource("MethodWithBaseReturn")>]
Expand Down
2 changes: 0 additions & 2 deletions TUnit.TestProject.FSharp/Inject_SharedInstancePerKey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ open TUnit.Core
module SharedInjectedKeyedContainer =
let instancesPerKey = ConcurrentDictionary<string, ResizeArray<DummyReferenceTypeClass>>()

type DummyReferenceTypeClass() = class end

[<ClassDataSource(typeof<DummyReferenceTypeClass>, Shared=SharedType.PerClass)>]
[<NotInParallel>]
type InjectSharedPerKey1(dummyReferenceTypeClass: DummyReferenceTypeClass) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ open System.Threading.Tasks
open TUnit.Core
open TUnit.Core.Interfaces

[<ClassDataSource(typeof<InjectedClassDataSourceWithAsyncInitializerTests.MyClass>, Shared=SharedType.Keyed, Key="MyKey")>]
type InjectedClassDataSourceWithAsyncInitializerTests(myClass: InjectedClassDataSourceWithAsyncInitializerTests.MyClass) =

type MyClass() =
interface IAsyncInitializer with
member _.InitializeAsync() =
Console.WriteLine("IAsyncInitializer.InitializeAsync")
Task.CompletedTask

[<ClassDataSource(typeof<MyClass>, Shared=SharedType.Keyed, Key="MyKey")>]
type InjectedClassDataSourceWithAsyncInitializerTests(myClass: MyClass) =
[<Before(HookType.Test)>]
member _.BeforeTest() : Task =
Console.WriteLine("BeforeTest")
Expand All @@ -26,9 +33,3 @@ type InjectedClassDataSourceWithAsyncInitializerTests(myClass: InjectedClassData
member _.Test3() : Task =
Console.WriteLine("Test")
Task.CompletedTask

type MyClass() =
interface IAsyncInitializer with
member _.InitializeAsync() =
Console.WriteLine("IAsyncInitializer.InitializeAsync")
Task.CompletedTask