Skip to content

Commit

Permalink
XUnit2ProviderFeature added in TechTalk.SpecFlow.Specs.
Browse files Browse the repository at this point in the history
Use of xunit.runner.console V2.
Xunit2TestGeneratorProvider updated to generate IClassFixture instead of ICollectionFixture.
  • Loading branch information
ivanrusso committed Jun 2, 2015
1 parent 0138f5d commit 682cf34
Show file tree
Hide file tree
Showing 18 changed files with 2,869 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .nuget/packages.config
Expand Up @@ -2,5 +2,5 @@
<packages>
<package id="NuGet.CommandLine" version="2.8.3" />
<package id="NUnit.Runners" version="2.6.4" />
<package id="xunit.runners" version="1.9.2" />
<package id="xunit.runner.console" version="2.0.0" />
</packages>
2 changes: 1 addition & 1 deletion Generator/TechTalk.SpecFlow.Generator.csproj
Expand Up @@ -118,7 +118,7 @@
<Compile Include="UnitTestProvider\MsTestSilverlightGeneratorProvider.cs" />
<Compile Include="UnitTestProvider\MbUnitTestGeneratorProvider.cs" />
<Compile Include="UnitTestProvider\MsTest2010GeneratorProvider.cs" />
<Compile Include="UnitTestProvider\X2UnitTestGeneratorProvider.cs" />
<Compile Include="UnitTestProvider\XUnit2TestGeneratorProvider.cs" />
<Compile Include="UnitTestProvider\XUnitTestGeneratorProvider.cs" />
<Compile Include="UnitTestProvider\IUnitTestGeneratorProvider.cs" />
<Compile Include="UnitTestProvider\MsTestGeneratorProvider.cs" />
Expand Down
Expand Up @@ -9,9 +9,13 @@ namespace TechTalk.SpecFlow.Generator.UnitTestProvider
public class XUnit2TestGeneratorProvider : XUnitTestGeneratorProvider
{
private const string FEATURE_TITLE_PROPERTY_NAME = "FeatureTitle";
private const string FACT_ATTRIBUTE = "Xunit.FactAttribute";
private const string FACT_ATTRIBUTE_SKIP_PROPERTY_NAME = "Skip";
private const string THEORY_ATTRIBUTE = "Xunit.TheoryAttribute";
private const string THEORY_ATTRIBUTE_SKIP_PROPERTY_NAME = "Skip";
private const string INLINEDATA_ATTRIBUTE = "Xunit.InlineDataAttribute";
private const string ICOLLECTIONFIXTURE_INTERFACE = "Xunit.ICollectionFixture";
private const string SKIP_REASON = "Ignored";
private const string ICLASSFIXTURE_INTERFACE = "Xunit.IClassFixture";

public XUnit2TestGeneratorProvider(CodeDomHelper codeDomHelper)
:base(codeDomHelper)
Expand All @@ -21,7 +25,7 @@ public XUnit2TestGeneratorProvider(CodeDomHelper codeDomHelper)

protected override CodeTypeReference CreateFixtureInterface(CodeTypeReference fixtureDataType)
{
return new CodeTypeReference(ICOLLECTIONFIXTURE_INTERFACE, fixtureDataType);
return new CodeTypeReference(ICLASSFIXTURE_INTERFACE, fixtureDataType);
}

public override void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
Expand All @@ -48,5 +52,32 @@ public override void SetRowTest(TestClassGenerationContext generationContext, Co

CodeDomHelper.AddAttribute(testMethod, INLINEDATA_ATTRIBUTE, args.ToArray());
}

public override void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
{
var factAttr = testMethod.CustomAttributes.OfType<CodeAttributeDeclaration>()
.FirstOrDefault(codeAttributeDeclaration => codeAttributeDeclaration.Name == FACT_ATTRIBUTE);

if (factAttr != null)
{
// set [FactAttribute(Skip="reason")]
factAttr.Arguments.Add
(
new CodeAttributeArgument(FACT_ATTRIBUTE_SKIP_PROPERTY_NAME, new CodePrimitiveExpression(SKIP_REASON))
);
}

var theoryAttr = testMethod.CustomAttributes.OfType<CodeAttributeDeclaration>()
.FirstOrDefault(codeAttributeDeclaration => codeAttributeDeclaration.Name == THEORY_ATTRIBUTE);

if (theoryAttr != null)
{
// set [TheoryAttribute(Skip="reason")]
theoryAttr.Arguments.Add
(
new CodeAttributeArgument(THEORY_ATTRIBUTE_SKIP_PROPERTY_NAME, new CodePrimitiveExpression(SKIP_REASON))
);
}
}
}
}
2 changes: 1 addition & 1 deletion Generator/UnitTestProvider/XUnitTestGeneratorProvider.cs
Expand Up @@ -176,7 +176,7 @@ public void SetTestClassIgnore(TestClassGenerationContext generationContext)
//TODO: how to do class level ignore?
}

public void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
public virtual void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
{
var factAttr = testMethod.CustomAttributes.OfType<CodeAttributeDeclaration>()
.FirstOrDefault(codeAttributeDeclaration => codeAttributeDeclaration.Name == FACT_ATTRIBUTE);
Expand Down
Expand Up @@ -284,7 +284,8 @@ xcopy $(SolutionDir)packages\xunit.1.9.2\lib\net20\*.* $(TargetDir)xunit\lib\ /s

xcopy $(SolutionDir)packages\xunit.extensions.1.9.2\lib\net20\*.* $(TargetDir)xunit.extensions\lib\ /s /y

xcopy $(SolutionDir)packages\xunit.runners.1.9.2\*.* $(TargetDir)xunit.runners\ /s /y
xcopy $(SolutionDir)packages\xunit.runner.console.2.0.0\*.* $(TargetDir)xunit.runner.console\ /s /y


xcopy $(SolutionDir)lib\mbunit.3.3.442.0\*.* $(TargetDir)mbUnit3\ /s /y

Expand Down
Expand Up @@ -72,6 +72,9 @@ public IEnumerable<string> GetAdditionalReferences()
break;
case "xunit":
yield return @"xUnit2\xunit.core.dll";
yield return @"xUnit2\xunit.abstractions.dll";
yield return @"xUnit2\xunit.assert.dll";
yield return @"xUnit2\xunit.execution.desktop.dll";
break;
}
}
Expand Down
Expand Up @@ -23,10 +23,10 @@ public TestRunSummary Execute()
{
string resultFilePath = Path.Combine(inputProjectDriver.DeploymentFolder, "xunit-result.xml");
string logFilePath = Path.Combine(inputProjectDriver.DeploymentFolder, "xunit-result.txt");
var xunitConsolePath = Path.Combine(AssemblyFolderHelper.GetTestAssemblyFolder(), @"xunit.runners\tools\xunit.console.clr4.exe");
var xunitConsolePath = Path.Combine(AssemblyFolderHelper.GetTestAssemblyFolder(), @"xunit.runner.console\tools\xunit.console.exe");

var provessHelper = new ProcessHelper();
provessHelper.RunProcess(xunitConsolePath, "\"{0}\" /nunit \"{1}\"",
provessHelper.RunProcess(xunitConsolePath, "\"{0}\" -nunit \"{1}\"",
inputProjectDriver.CompiledAssemblyPath, resultFilePath);

File.WriteAllText(logFilePath, provessHelper.ConsoleOutput);
Expand Down
88 changes: 88 additions & 0 deletions Tests/TechTalk.SpecFlow.Specs/Features/XUnit2Provider.feature
@@ -0,0 +1,88 @@
Feature: XUnit v2 unit test provider

Scenario Outline: Should be able to execute scenarios with basic results
Given there is a SpecFlow project
And the project is configured to use the xUnit provider
And a scenario 'Simple Scenario' as
"""
When I do something
"""
And all steps are bound and <step definition status>
When I execute the tests with xUnit
Then the execution summary should contain
| Total | <result> |
| 1 | 1 |

Examples:
| result | step definition status |
| Succeeded | pass |
| Failed | fail |

Scenario: Should be able to ignore a scenario outline
Given there is a SpecFlow project
And the project is configured to use the xUnit provider
And there is a feature file in the project as
"""
Feature: Simple Feature
@ignore
Scenario Outline: Simple Scenario Outline
Given there is something
When I do <what>
Then something should happen
Examples:
| what |
| something |
| something else |
"""
And all steps are bound and pass
When I execute the tests with xUnit
Then the execution summary should contain
| Succeeded |
| 0 |

Scenario Outline: Should handle scenario outlines
Given there is a SpecFlow project
And the project is configured to use the xUnit provider
And row testing is <row test>
Given there is a feature file in the project as
"""
Feature: Simple Feature
Scenario Outline: Simple Scenario Outline
Given there is something
When I do <what>
Then something should happen
Examples:
| what |
| something |
| something else |
"""
And all steps are bound and pass
When I execute the tests with xUnit
Then the execution summary should contain
| Succeeded |
| 2 |

Examples:
| case | row test |
| Normal testing | disabled |
| Row testing | enabled |

@config
Scenario: Should be able to specify xUnit provider in the configuration
Given there is a SpecFlow project
And a scenario 'Simple Scenario' as
"""
When I do something
"""
And all steps are bound and pass
And the specflow configuration is
"""
<specFlow>
<unitTestProvider name="xUnit"/>
</specFlow>
"""
When I execute the tests with xUnit
Then the execution summary should contain
| Total |
| 1 |

0 comments on commit 682cf34

Please sign in to comment.