Skip to content

Commit

Permalink
Using steps defined in other assemblies.
Browse files Browse the repository at this point in the history
Enable writing steps in VB.
Cleaning up ContextInjection
  • Loading branch information
jbandi committed Feb 11, 2010
1 parent 0c0b268 commit 20461dc
Show file tree
Hide file tree
Showing 23 changed files with 827 additions and 38 deletions.
31 changes: 31 additions & 0 deletions Runtime/Configuration/ConfigurationSectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public TraceConfigElement Trace
set { this["trace"] = value; }
}

[ConfigurationProperty("stepAssemblies", IsDefaultCollection = false, IsRequired = false)]
[ConfigurationCollection(typeof(StepAssemblyCollection), AddItemName = "stepAssembly")]
public StepAssemblyCollection StepAssemblies
{
get { return (StepAssemblyCollection)this["stepAssemblies"]; }
set { this["stepAssemblies"] = value; }
}

static internal ConfigurationSectionHandler CreateFromXml(string xmlContent)
{
ConfigurationSectionHandler section = new ConfigurationSectionHandler();
Expand Down Expand Up @@ -229,4 +237,27 @@ public string Listener
set { this["listener"] = value; }
}
}

public class StepAssemblyCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new StepAssemblyConfigElement();
}

protected override object GetElementKey(ConfigurationElement element)
{
return ((StepAssemblyConfigElement) element).File;
}
}

public class StepAssemblyConfigElement : ConfigurationElement
{
[ConfigurationProperty("file", DefaultValue = null, IsRequired = false)]
public string File
{
get { return (string)this["file"]; }
set { this["file"] = value; }
}
}
}
20 changes: 20 additions & 0 deletions Runtime/Configuration/RuntimeConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using TechTalk.SpecFlow.Tracing;
using TechTalk.SpecFlow.UnitTestProvider;

Expand All @@ -15,6 +18,8 @@ public partial class ConfigurationSectionHandler

internal class RuntimeConfiguration
{
private List<Assembly> _additionalStepAssemblies = new List<Assembly>();

static public RuntimeConfiguration Current
{
get { return ObjectContainer.Configuration; }
Expand All @@ -37,6 +42,13 @@ static public RuntimeConfiguration Current
public bool TraceTimings { get; set; }
public TimeSpan MinTracedDuration { get; set; }

public IEnumerable<Assembly> AdditionalStepAssemblies
{
get {
return _additionalStepAssemblies;
}
}

public RuntimeConfiguration()
{
ToolLanguage = string.IsNullOrEmpty(ConfigDefaults.ToolLanguage) ?
Expand Down Expand Up @@ -103,6 +115,14 @@ public static RuntimeConfiguration LoadFromConfigFile(ConfigurationSectionHandle
config.MinTracedDuration = configSection.Trace.MinTracedDuration;
}

foreach(var element in configSection.StepAssemblies)
{
string stepAssemblyFileName = ((StepAssemblyConfigElement)element).File;
string fullPath = Path.GetFullPath(stepAssemblyFileName);
Assembly stepAssembly = Assembly.LoadFile(fullPath);
config._additionalStepAssemblies.Add(stepAssembly);
}

return config;
}

Expand Down
7 changes: 6 additions & 1 deletion Runtime/ObjectContainer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using TechTalk.SpecFlow.Configuration;
using TechTalk.SpecFlow.ErrorHandling;
using TechTalk.SpecFlow.Tracing;
using TechTalk.SpecFlow.UnitTestProvider;
using System.Linq;

namespace TechTalk.SpecFlow
{
Expand Down Expand Up @@ -53,7 +55,10 @@ internal static ITestRunner EnsureTestRunner(Assembly callingAssembly)
var result = new TestRunner();

List<Assembly> bindingAssemblies = new List<Assembly>();
bindingAssemblies.Add(callingAssembly); //TODO: add more assemblies from config
bindingAssemblies.Add(callingAssembly);

bindingAssemblies.AddRange(configuration.AdditionalStepAssemblies);

result.InitializeTestRunner(bindingAssemblies.ToArray());

return result;
Expand Down
14 changes: 14 additions & 0 deletions TechTalk.SpecFlow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechTalk.SpecFlow.Tools", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureTests", "Tests\FeatureTests\FeatureTests.csproj", "{3FE793A8-E662-4026-B4EC-891324073235}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ExternalStepsVB", "Tests\FeatureTests\ExternalSteps\ExternalStepsVB\ExternalStepsVB.vbproj", "{D3F6B835-B228-4DCF-B533-B6ED469A33B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExternalStepsCS", "Tests\FeatureTests\ExternalSteps\ExternalStepsCS\ExternalStepsCS.csproj", "{3836A6FC-4ECC-413A-AC8F-83A0A773EC9E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -87,6 +91,14 @@ Global
{3FE793A8-E662-4026-B4EC-891324073235}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FE793A8-E662-4026-B4EC-891324073235}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FE793A8-E662-4026-B4EC-891324073235}.Release|Any CPU.Build.0 = Release|Any CPU
{D3F6B835-B228-4DCF-B533-B6ED469A33B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3F6B835-B228-4DCF-B533-B6ED469A33B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3F6B835-B228-4DCF-B533-B6ED469A33B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3F6B835-B228-4DCF-B533-B6ED469A33B3}.Release|Any CPU.Build.0 = Release|Any CPU
{3836A6FC-4ECC-413A-AC8F-83A0A773EC9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3836A6FC-4ECC-413A-AC8F-83A0A773EC9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3836A6FC-4ECC-413A-AC8F-83A0A773EC9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3836A6FC-4ECC-413A-AC8F-83A0A773EC9E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -97,5 +109,7 @@ Global
{70376361-0BE1-478D-8EEC-47BD1C768165} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{F8FACCF0-5497-4C6B-861F-78D72FD9561B} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{3FE793A8-E662-4026-B4EC-891324073235} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{D3F6B835-B228-4DCF-B533-B6ED469A33B3} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{3836A6FC-4ECC-413A-AC8F-83A0A773EC9E} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
EndGlobalSection
EndGlobal
30 changes: 30 additions & 0 deletions Tests/FeatureTests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>

<specFlow>
<language feature="en" tool="en" />

<unitTestProvider name="NUnit"/>

<generator allowDebugGeneratedFiles="false" />

<runtime detectAmbiguousMatches="true"
stopAtFirstError="false"
missingOrPendingStepsOutcome="Inconclusive" />

<trace traceSuccessfulSteps="true"
traceTimings="false"
minTracedDuration="0:0:0.1"
listener="TechTalk.SpecFlow.Tracing.DefaultListener, TechTalk.SpecFlow"
/>

<stepAssemblies>
<stepAssembly file="..\..\ExternalSteps\ExternalStepsVB\bin\debug\ExternalStepsVB.dll" />
<stepAssembly file="..\..\ExternalSteps\ExternalStepsCS\bin\debug\ExternalStepsCS.dll" />
</stepAssemblies>

</specFlow>
</configuration>
81 changes: 53 additions & 28 deletions Tests/FeatureTests/ContextInjection/ContextInjection.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Tests/FeatureTests/ExternalSteps/ExternalSteps.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: External Step Definitions
In order to modularize my solution
As a bdd enthusiast
I want to use step definitions from other assemblies

Scenario: Steps defined in an external VB project and an external c-sharp project
Given I have external step definitions in a separate assembly referenced by this project
When I call those steps
Then the scenario should pass
71 changes: 71 additions & 0 deletions Tests/FeatureTests/ExternalSteps/ExternalSteps.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 20461dc

Please sign in to comment.