Skip to content
Merged
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions docs/docs/test-authoring/depends-on.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public async Task AssertItemsInDatabase()
```

## Getting other tests
If your tests depends on another test, it's possible to retrieve that test's context. This allows you to do things like check its result, or retrieve objects from its object bag.
If your tests depends on another test, it's possible to retrieve that test's context. This allows you to do things like check its result, or retrieve objects from its state bag.

This is done by calling the `GetTests` method on a `TestContext` object. It takes the test's method name (so you can use `nameof(...)`) and optionally the parameter types for if there's multiple overloads.
This is done by calling the `GetTests` method on the `TestContext.Dependencies` property. It takes the test's method name (so you can use `nameof(...)`) and optionally the parameter types for if there's multiple overloads.

You'll notice this returns an array - This is because tests may be data driven and be invoked multiple times - If this is the case you'll have to find the one you want yourself.

Expand All @@ -119,15 +119,15 @@ Example:
public async Task AddItemToBag()
{
var itemId = await AddToBag();
TestContext.Current!.StateBag.Add("ItemId", itemId);
TestContext.Current!.StateBag.Items["ItemId"] = itemId;
}

[Test]
[DependsOn(nameof(AddItemToBag))]
public async Task DeleteItemFromBag()
{
var addToBagTestContext = TestContext.Current!.GetTests(nameof(AddItemToBag)).First();
var itemId = addToBagTestContext.StateBag["ItemId"];
var addToBagTestContext = TestContext.Current!.Dependencies.GetTests(nameof(AddItemToBag)).First();
var itemId = addToBagTestContext.StateBag.Items["ItemId"];
await DeleteFromBag(itemId);
}
```
Expand Down
Loading