Skip to content

Commit

Permalink
Improve Unit Test Provider documentation (#2037)
Browse files Browse the repository at this point in the history
* Improve Unit Test Provider documentation

* fixed C&P error

* new NUnit format

* improve unit test providers
  • Loading branch information
SabotageAndi authored Jul 8, 2020
1 parent d9ca935 commit 8fe50bb
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 101 deletions.
10 changes: 0 additions & 10 deletions docs/Installation/.NET-Support.md

This file was deleted.

60 changes: 9 additions & 51 deletions docs/Installation/Unit-Test-Providers.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
# Unit Test Providers

**Note:** This information only applies to Full Framework projects using the `app.config` file to configure SpecFlow. For .NET Core and projects using `specflow.json` to configure SpecFlow, you need to add a NuGet package to your project to determine your unit test provider, see [SpecFlow-and-.NET-Core](SpecFlow-and-.NET-Core.md),
SpecFlow supports several unit test framework you can use to execute your tests.

SpecFlow supports several unit test framework you can use to execute your tests. In addition to using the built-in unit test providers, you can also create a custom provider. Use the [<unitTestProvider>](../Configuration/Configuration.md) configuration element in your `app.config` file to specify which unit test provider you want to use.
To use a specific unit test provider, you have to add it's dedicated NuGet package to your project.
You can only have one of these packages added to your project at once.

The following table contains the built-in unit test providers.

<table>
<tr>
<th rowspan="2">Name</th>
<th colspan="3">Supports</th>
<th rowspan="2">Description</th>
</tr>
<tr>
<th>row tests</th>
<th>categories</th>
<th>inconclusive</th>
</tr>
<tr>
<td>SpecFlow+ Runner (fka SpecRun)</td>
<td>+</td>
<td>+</td>
<td>+</td>
<td>[SpecFlow+ Runner](http://www.specflow.org/plus/runner/) is a dedicated test execution framework for SpecFlow. Install it with the SpecRun.SpecFlow NuGet package. See [SpecRun Integration]() for details.</td>
</tr>
<tr>
<td>NUnit</td>
<td>+</td>
<td>+</td>
<td>+</td>
<td>See [http://www.nunit.org](http://www.nunit.org). Specialized [NuGet packages](NuGet-Packages.md) available for easy setup: SpecFlow.NUnit, SpecFlow.NUnit.Runners. Supports parallel execution with NUnit v3. </td>
</tr>
<tr>
<td>MsTest.2008</td>
<td>-</td>
<td>-</td>
<td>+</td>
<td>MsTest provider for .NET 3.5</td>
</tr>
<tr>
<td>MsTest <br/> MsTest.2010</td>
<td>-</td>
<td>+</td>
<td>+</td>
<td>MsTest provider for .NET 4.0. Supports test categories. Specialized [NuGet package|NuGet Integration]() available for easy setup: SpecFlow.MsTest.</td>
</tr>
<tr>
<td>xUnit</td>
<td>+</td>
<td>-</td>
<td>-</td>
<td>See [http://www.xunit.net](). Specialized [NuGet package|NuGet Integration]() available for easy setup: SpecFlow.xUnit. Supports parallel execution with xUnit v2.</td>
</tr>
</table>
| Name | NuGet Package | Integration | Description |
| -----|---------------|-------------|-------------|
| SpecFlow+ Runner (fka SpecRun) | [SpecRun.SpecFlow](https://www.nuget.org/packages/SpecRun.SpecFlow/) | [goto Integration](../Integrations/SpecFlow+Runner-Integration.html) | [SpecFlow+ Runner](http://www.specflow.org/plus/runner/) is a dedicated test execution framework for SpecFlow. |
| xUnit | [SpecFlow.xUnit](https://www.nuget.org/packages/SpecFlow.xUnit/) | [goto Integration](../Integrations/xUnit.html) | See <http://www.xunit.net> |
| NUnit | [SpecFlow.NUnit](https://www.nuget.org/packages/SpecFlow.NUnit/) | [goto Integration](../Integrations/NUnit.html) | See <http://www.nunit.org> |
| MSTest | [SpecFlow.MsTest](https://www.nuget.org/packages/SpecFlow.MsTest/) | [goto Integration](../Integrations/MsTest.html) | See <https://github.com/microsoft/testfx>|
79 changes: 41 additions & 38 deletions docs/Integrations/MsTest.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
# MSTest

## Test Class Attributes
SpecFlow does support MsTest V2. It is not any more working with the old MsTest V1.

Documentation for MSTest can be found [here](https://docs.microsoft.com/en-us/visualstudio/test/unit-test-your-code?view=vs-2019).

## Needed NuGet Packages

For SpecFlow: [SpecFlow.MSTest](https://www.nuget.org/packages/SpecFlow.MSTest/)

For MSTest: [MSTest.TestFramework](https://www.nuget.org/packages/MSTest.TestFramework/)

For Test Discovery & Execution:

- [MSTest.TestAdapter](https://www.nuget.org/packages/MSTest.TestAdapter/)
- [Microsoft.NET.Test.Sdk](https://www.nuget.org/packages/Microsoft.NET.Test.Sdk)

## Accessing TestContext

``` csharp
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class MyStepDefs
{
private readonly TestContext _testContext;
public MyStepDefs(TestContext testContext) // use it as ctor parameter
{
_testContext = testContext;
}

[BeforeScenario()]
public void BeforeScenario()
{
//now you can access the TestContext
}
}
```

## Tags for TestClass Attributes

The MsTest Generator can generate test class attributes from tags specified on a **feature**.

Expand All @@ -14,7 +50,7 @@ Tag:

Output:

``` gherkin
``` csharp
[Microsoft.VisualStudio.TestTools.UnitTesting.OwnerAttribute("John")]
```

Expand All @@ -28,7 +64,7 @@ Tag:

Output:

``` gherkin
``` csharp
[Microsoft.VisualStudio.TestTools.UnitTesting.WorkItemAttribute(123)]
```

Expand All @@ -44,7 +80,7 @@ Tag:

Output:

``` gherkin
``` csharp
[Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("test.txt")]
```

Expand All @@ -58,39 +94,6 @@ Tag:

Output:

``` gherkin
[Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("Resources\\DeploymentItemTestFile.txt", "Data")]
```

## Accessing `TestContext`

### Using Context Injection

``` csharp
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class MyStepDefs
{
private readonly TestContext _testContext;
public MyStepDefs(TestContext testContext) // use it as ctor parameter
{
_testContext = testContext;
}

[BeforeScenario()]
public void BeforeScenario()
{
//now you can access the TestContext
}
}
```

### Using the Scenario Container

``` csharp
[Given(@"my test step definition")]
public void MyStepDefinition()
{
var testContext = ScenarioContext.Current.ScenarioContainer.Resolve<Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>();
}
[Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("Resources\\DeploymentItemTestFile.txt", "Data")]
```
16 changes: 16 additions & 0 deletions docs/Integrations/NUnit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# NUnit

SpecFlow supports NUnit 3.11 or later.

Documentation for NUnit can be found [here](https://github.com/nunit/docs/wiki/NUnit-Documentation).

## Needed NuGet Packages

For SpecFlow: [SpecFlow.NUnit](https://www.nuget.org/packages/SpecFlow.NUnit/)

For NUnit: [NUnit](https://www.nuget.org/packages/NUnit/)

For Test Discovery & Execution:

- [NUnit3TestAdapter](https://www.nuget.org/packages/NUnit3TestAdapter/)
- [Microsoft.NET.Test.Sdk](https://www.nuget.org/packages/Microsoft.NET.Test.Sdk)
44 changes: 44 additions & 0 deletions docs/Integrations/xUnit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# xUnit

SpecFlow supports xUnit 2.4 or later.

Documentation for NUnit can be found [here](https://xunit.net/#documentation).

## Needed NuGet Packages

For SpecFlow: [SpecFlow.xUnit](https://www.nuget.org/packages/SpecFlow.xUnit/)

For xUnit: [xUnit](https://www.nuget.org/packages/xunit/)

For Test Discovery & Execution:

- [xunit.runner.visualstudio](https://www.nuget.org/packages/xunit.runner.visualstudio/)
- [Microsoft.NET.Test.Sdk](https://www.nuget.org/packages/Microsoft.NET.Test.Sdk)

## Access ITestOutputHelper

The xUnit ITestOutputHelper is registered in the ScenarioContainer. You can get access to simply via getting it via [Context-Injection](../Bindings/Context-Injection.md).

### Example

``` csharp

using System;
using TechTalk.SpecFlow;
[Binding]
public class BindingClass
{
private Xunit.Abstractions.ITestOutputHelper _testOutputHelper;
public StepsWithScenarioContext(Xunit.Abstractions.ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

[When(@"I do something")]
public void WhenIDoSomething()
{
_output.WriteLine("EB7C1291-2C44-417F-ABB7-A5154843BC7B");
}
}

```
7 changes: 5 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Indices and tables
Installation/NuGet-Packages.md
Installation/Project-and-Item-Templates.md
Installation/Troubleshooting-Visual-Studio-Integration.md
Installation/.NET-Support.md
Installation/Unit-Test-Providers.md
Installation/SpecFlow-and-.NET-Core.md
Installation/Breaking-Changes-with-SpecFlow-3.0.md
Expand Down Expand Up @@ -116,8 +115,12 @@ Indices and tables
:caption: Integrations
:hidden:

Integrations/MsTest.md

Integrations/SpecFlow+Runner-Integration.md
Integrations/MsTest.md
Integrations/NUnit.md
Integrations/xUnit.md

Integrations/Azure-DevOps.md
Integrations/Teamcity-Integration.md
Integrations/Browserstack.md
Expand Down

0 comments on commit 8fe50bb

Please sign in to comment.