Delay between tests #908
Answered
by
thomhurst
borislavml
asked this question in
Q&A
-
Is there a "nice and clean" way to delay execution between two particular tests using attributes or something? Or is it possible to write such a custom attribute? I can certainly do the following which is of course not ideal and not a good practice but in the real-world when integration testing one has to do such thing.
|
Beta Was this translation helpful? Give feedback.
Answered by
thomhurst
Oct 15, 2024
Replies: 1 comment 1 reply
-
Creating a custom TestExecutor should be able to achieve this. public class DelayedExecutor : GenericAbstractExecutor
{
private static bool _hasRun;
protected override async Task ExecuteAsync(Func<Task> action)
{
if (Interlocked.Exchange(ref _hasRun, true))
{
await Task.Delay(10_000);
}
await action();
}
} [TestExecutor<DelayedExecutor>]
public class MyTests
{
[Test]
public async Task Test1()
{
// do some stuff which results in a message sent on a queue
}
[Test]
[DependsOn(nameof(Test1))]
public async Task Test2()
{
// wait on a queue to read from the messsage as a result of the "do some stuff" in Test1
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
borislavml
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Creating a custom TestExecutor should be able to achieve this.