Skip to content

Commit 8095332

Browse files
authored
Add info for AddAsyncTestBlock
1 parent f3d516d commit 8095332

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,41 @@ public void Test1()
8383
This takes care of needing to have code in the test to wire up the logger, Selenium / WebDriver, and will produce errors if you (for example) add a test black that needs a dependency that isn't supplied by the test. This gives you an easy way to move complex code out of your tests and expose human-readable hooks for composing tests.
8484

8585
See the full code here: [Example Tests](https://github.com/IntelliTect/TestTools.TestFramework/tree/update-docs/ExampleTests/ExampleTests)
86+
87+
Async/Await
88+
-----
89+
TestFramework now supports test blocks that need to be awaited. Please be aware that deviating that from the standard async/await with Task or Task<T> return types can result in unexpected behavior. If you encounter these scenarios, please file an issue so we can look into it.
90+
91+
For ease of use and explicit test authoring, there is a method to tell TestFramework if a TestBlock is awaitable. Let's say you have the following test block:
92+
93+
```
94+
using IntelliTect.TestTools.TestFramework;
95+
96+
namespace ExampleTests.TestBlocks;
97+
98+
internal class VerifyAwait : ITestBlock
99+
{
100+
public async Task Execute()
101+
{
102+
await Task.Delay(1);
103+
}
104+
}
105+
```
106+
107+
To properly await this, you would build and execute your test case like so:
108+
```
109+
[Fact]
110+
public void Test1()
111+
{
112+
TestBuilder builder = new();
113+
114+
builder.AddAsyncTestBlock<TestBlocks.VerifyAwait>()
115+
116+
TestCase test = builder.Build()
117+
test.ExecuteAsync();
118+
}
119+
```
120+
121+
Also note that current behavior is that TestFramework will take the result of the awaited test block task and use that for future test block dependencies. If you have a test block that returns Task<bool>, TestFramework will capture the bool result to use.
122+
123+
More in depth examples are coming later!

0 commit comments

Comments
 (0)