Interrogator is a collection of packages to support integration testing. Using Interrogator, complex relationships between unit tests can be defined.
- Add
Interrogator.xUnit
package to your test project - Add the
[IntegrationTest]
attribute to the top of any test method
[IntegrationTest]
public Task Test1()
{
// Do something
}
The DependsOn
attribute can be used to ensure that all dependencies are executed before the tagged method. Multiple DependsOn
attributes can exist on a single test. Best practice is to use nameof
to indicate the dependency.
When running explicit tests that is further in the dependency tree, all ancestor dependencies will be executed prior to the test or tests run.
Note: Failing tests earlier in the dependency tree will result in later tests not being run. When running a single test, this may result in the appearance that the test being run was skipped without other tests failing.
[IntegrationTest]
public Task Test1()
{
// Do something
}
[IntegrationTest]
[DependsOn(nameof(Test1))]
public Task Test2()
{
// Do something
}
Tests that must not be executed at the same time can be marked with the NotConcurrent
attribute. Multiple NotConcurrent
attriutes can exist on a single test.
groupName
(string)- When provided, all
NotConcurrent
attributes with the samegroupName
will not be executed concurrently. It is possible forNotConcurrent
groups with a differentgroupName
to execute at the same time.
- When provided, all
- ConcurrencyScope (enum)
- Class - Default - All
groupName
s within the same class will be considered a singleNotConcurrent
group. - ClassHierarchy - All
groupName
s within the same class hierarchy will be considered a singleNotConcurrent
group. - Namespace - All
groupName
s within the same namespace will be considered a singleNotConcurrent
group. - Assembly - All
groupName
s within the same assembly will be consider a singleNotConcurrent
group.
- Class - Default - All
[IntegrationTest]
[NotConcurrent]
public Task Test1()
{
// Do something
}
[IntegrationTest]
[NotConcurrent]
public Task Test2()
{
// Do something
}
The FromAttribute
can be used to indicate a parameter dependency. This dependency can be the output of another test, or a static method.
Note: If this is the output of a static method, the static method will be run once the output will be used for all instances of that FromAttribute
public static InitialData CreateInitialData()
=> new InitialData();
[IntegrationTest]
public Task Test([From(nameof(CreateInitialData))]InitialData initialData)
{
// Do something
}
[IntegrationTest]
public Task Test1()
{
// Do something
return "A string";
}
[IntegrationTest]
public Task Test2([From(nameof(Test1))]string test1String)
{
// Do something
}
xUnit specific package to allow integration with xUnit tests.