-
-
Notifications
You must be signed in to change notification settings - Fork 109
Fix generic DependsOn<T> attribute not working #4246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||||||||||||||||||||
| using TUnit.TestProject.Attributes; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| namespace TUnit.TestProject; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Test class with test methods to depend on | ||||||||||||||||||||||||||||
| public class GenericDependsOnTestsClassA | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| internal static DateTime Test1Start; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| [Test] | ||||||||||||||||||||||||||||
| public async Task Test1() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Test1Start = TestContext.Current!.Execution.TestStart!.Value.DateTime; | ||||||||||||||||||||||||||||
| await Task.Delay(TimeSpan.FromSeconds(5)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Test for generic DependsOn with method name: DependsOn<T>(methodName) | ||||||||||||||||||||||||||||
| [EngineTest(ExpectedResult.Pass)] | ||||||||||||||||||||||||||||
| public class GenericDependsOnTestsWithClass | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| private static DateTime _test2Start; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| [Test, DependsOn<GenericDependsOnTestsClassA>(nameof(GenericDependsOnTestsClassA.Test1))] | ||||||||||||||||||||||||||||
| public async Task Test2() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| _test2Start = TestContext.Current!.Execution.TestStart!.Value.DateTime; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| await Task.CompletedTask; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| [After(Class)] | ||||||||||||||||||||||||||||
| public static async Task AssertStartTimes() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| await Assert.That(_test2Start).IsAfterOrEqualTo(GenericDependsOnTestsClassA.Test1Start.AddSeconds(4.9)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Test class with test methods to depend on for the second test | ||||||||||||||||||||||||||||
| public class GenericDependsOnTestsClassB | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| internal static DateTime Test1Start; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| [Test] | ||||||||||||||||||||||||||||
| public async Task Test1() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Test1Start = TestContext.Current!.Execution.TestStart!.Value.DateTime; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| await Task.Delay(TimeSpan.FromSeconds(5)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Test for generic DependsOn without method name: DependsOn<T>() | ||||||||||||||||||||||||||||
| // This should depend on all tests in ClassB | ||||||||||||||||||||||||||||
| [EngineTest(ExpectedResult.Pass)] | ||||||||||||||||||||||||||||
| public class GenericDependsOnTestsWithClassNoMethod | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| private static DateTime _test2Start; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| [Test, DependsOn<GenericDependsOnTestsClassB>] | ||||||||||||||||||||||||||||
| public async Task Test2() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| _test2Start = TestContext.Current!.Execution.TestStart!.Value.DateTime; | ||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+61
|
||||||||||||||||||||||||||||
| [Test, DependsOn<GenericDependsOnTestsClassB>] | |
| public async Task Test2() | |
| { | |
| _test2Start = TestContext.Current!.Execution.TestStart!.Value.DateTime; | |
| private static void SetTest2Start(DateTime value) | |
| { | |
| _test2Start = value; | |
| } | |
| [Test, DependsOn<GenericDependsOnTestsClassB>] | |
| public async Task Test2() | |
| { | |
| SetTest2Start(TestContext.Current!.Execution.TestStart!.Value.DateTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write to static field from instance method, property, or constructor.