0

I use the specflow nunitexecutionreport command to produce html reports of my tests and I copy it to a folder where i have the timestamp of the, the report, the generated html and the screenshots taken upon success or failure(all done programatically). But the folder's html report does not have the feature file text of that time. I want to know how, for each test i can get the feature file text at runtime so i can copy it to that folder.

2 Answers2

0

This isn't really an answer but I need to give a formatted response so this will need editing later

Do you really need to this by rewriting the wheel, or at least do you really need to rewrite the test runner process?

For example the following output comes from TeamCity running NUnit over a specflow generated tests.

[20:29:38][MyCode.Tests.dll] MyCode.Tests.MyFeature.Reload
[20:29:38][MyCode.Tests.MyFeature.Reload] Given I have a config reloader
[20:29:38][MyCode.Tests.MyFeature.Reload] -> done: ConfigReloadTests.GivenIHaveAConfigReloader() (0.1s)
[20:29:38][MyCode.Tests.MyFeature.Reload] And a config A that will unload
[20:29:38][MyCode.Tests.MyFeature.Reload] -> done: ConfigReloadTests.GivenAConfig("A") (0.0s)
[20:29:38][MyCode.Tests.MyFeature.Reload] And a config B that wont unload
[20:29:38][MyCode.Tests.MyFeature.Reload] -> done: ConfigReloadTests.GivenAConfigThatWontUnload("B") (0.0s)
[20:29:38][MyCode.Tests.MyFeature.Reload] When I reload my configs
[20:29:38][MyCode.Tests.MyFeature.Reload] -> done: ConfigReloadTests.WhenIReloadMyConfigs() (0.3s)
[20:29:38][MyCode.Tests.MyFeature.Reload] Then I should have 2 instances
[20:29:38][MyCode.Tests.MyFeature.Reload] -> done: ConfigReloadTests.ThenIShouldHaveInstances(2) (0.1s)

Now this is a standard out of the box result, it would take maybe fifteen minutes to set up. Its fully supported, and its available free. Or do you need something custom that I'm missing from your question?

AlSki
  • 6,868
  • 1
  • 26
  • 39
0

IF you can guarantee you are using NUnit to run the Specflow tests then you can write an NUnitAddin which can pick up the Specflow output as it runs. I've previously done this for a personal project.

You register with one class

[NUnitAddin(
    Name = "RedGreenRefactor.DatCapture.NUnitAddIn", 
    Description = "Captures both test data and test output so that SpecFlow steps can be correctly consolidated by RedGreenRefactor",
    Type=ExtensionType.Core)]
public class Addin : IAddin
{       
    public bool Install(IExtensionHost host)
    {
       IExtensionPoint listeners = host.GetExtensionPoint("EventListeners");
        if ( listeners == null )
            return false;

        listeners.Install( new NUnitCapture() );
        return true;
    }       
}

And the core of your addin looks like this

public class NUnitCapture : NUnit.Core.EventListener 
{
...
public void TestOutput(NUnit.Core.TestOutput testOutput)
{
    var text = testOutput.Text.Trim();
    Debug.WriteLine(String.Format("[{0}]", text));
    if (text.StartsWith("Given")
        || text.StartsWith("When")
        || text.StartsWith("Then")
        || text.StartsWith("And"))
        {
            CreateStep(testOutput);
            return;
        }

        if (text.StartsWith("-> done"))
        {
            SetStepToSuccess();
            return;
        }

        if (text.StartsWith("-> error"))
        {
            SetStepToFail();
            return;
        }

        if (text.StartsWith("-> No matching step definition found for the step."))
        {
            SetStepToPending();
            return;
        }
    }
AlSki
  • 6,868
  • 1
  • 26
  • 39