Specflow suddenly stopped matching a step in Visual Studio

255 views
Skip to first unread message

Steinar Bang

unread,
Nov 16, 2016, 8:31:48 AM11/16/16
to spec...@googlegroups.com
Platform: Win 7 Enterprise
Visual Studio 2013 Professional (version 12.0.40629.00 Update 5)
JetBrains ReSharper Ultimate 2015.2 Build 103.0.20150818.200216
.Net Framework 4.6.0.01055
TechTalk Specflow extension version 2015.1
Gherkin with Norwegian as the l12n setting

I have been running a specflow scenario example repeatedly in the
resharper test sessions view, while working on a new "Then" step
ie. modifying the code in the step.

However, running the scenario example in the resharper test sessions
view suddenly started failing out of the blue, with the message:
Assert.Inconclusive failed. No matching step definition found for one or more steps.
and the step it expects to find but doesn't find, is:
[Then(@"(.*) er knyttet inn i refusjonsgruppe A(.*)AD(.*)_(.*) med (.*), NULL og NULL gitt som antall dager i forhold til idag\.")]
public void SaErKnyttetInnIRefusjonsgruppeAAD_MedNULLOgNULLGittSomAntallDagerIForholdTilIdag_(int p0, int p1, int p2, int p3, int p4)

This is also the signature resharper or Visual Studio says it doesn't
find, if I right-click the step in the .feature file and select: Go To Declaration

The weird thing here is that it looks like Visual Studio or ReSharper
suddenly has decided that "A06AD65_1" should be matched as "A(.*)AD(.*)_(.*)"

I have tried deleting the .cache file in %TEMP% but that didn't help.
What I did, was:
1. Stopped Visual Studio
2. Opened windows explorer on %TEMP%
3. Deleted the specflow*.cache file found in that directory
4. Started Visual Studio again

But the problem persists even after this.

Here's the step definition from the feature file:
Og <varenummer> er knyttet inn i refusjonsgruppe <RefGruppe> med <FradatoRefusjon>, <ForskrivesTilDato> og <UtleveresTildato> gitt som antall dager i forhold til idag.
("Og" is Norwegian for "And", this is a "Then" step)

Here's the example table that fills up <varenummer>, <RefGruppe" etc.:
Eksempler:
| Kommentar | Fil Nr | varenummer | H-reseptPris | Fradato_H-reseptPris | RefGruppe | FradatoRefusjon | ForskrivesTilDato | UtleveresTildato |
| | 1 | 015461 | 3054,23 | +15 | A06AD65_1 | -2954 | NULL | NULL |

Here's the method and its attribute, that suddenly no longer matched:
[Then(@"(.*) er knyttet inn i expectedRefusjonsgruppe ([a-zA-Z][a-zA-Z0-9#._-]+) med (.*), (.*) og (.*) gitt som antall dager i forhold til idag\.")]
public void ThenErKnyttetInnIRefusjonsgruppeMedNULLOgNULLGittSomAntallDagerIForholdTilIdag_(string varenummer, string refusjonsgruppe, string fraDato, string forskrivesTilDato, string utleveresTilDato)

The "([a-zA-Z][a-zA-Z0-9#._-]+)" used to be "(.*)" while it worked, I
just tried to make it more specific to see if that would fix things, but
it didn't.

Does anyone know what might have caused this problem?

Does anyone know how to fix the problem? Workarounds...?

Eg. is there some ReSharper cache that I could delete?

Thanks!


- Steinar

Sam Holder

unread,
Nov 16, 2016, 8:45:26 AM11/16/16
to specflow
Which version of the specflow nuget package are you using?

are you using a step which calls other steps?

does this step which calls other steps finish with a different step type (ie a when or a given)?



- Steinar

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steinar Bang

unread,
Nov 16, 2016, 8:47:35 AM11/16/16
to spec...@googlegroups.com
>>>>> Steinar Bang <s...@dod.no>:

> Platform: Win 7 Enterprise
> Visual Studio 2013 Professional (version 12.0.40629.00 Update 5)
> JetBrains ReSharper Ultimate 2015.2 Build 103.0.20150818.200216
> .Net Framework 4.6.0.01055
> TechTalk Specflow extension version 2015.1
> Gherkin with Norwegian as the l12n setting

> I have been running a specflow scenario example repeatedly in the
> resharper test sessions view, while working on a new "Then" step
> ie. modifying the code in the step.

> However, running the scenario example in the resharper test sessions
> view suddenly started failing out of the blue, with the message:
> Assert.Inconclusive failed. No matching step definition found for one or more steps.
> and the step it expects to find but doesn't find, is:
> [Then(@"(.*) er knyttet inn i refusjonsgruppe A(.*)AD(.*)_(.*) med (.*), NULL og NULL gitt som antall dager i forhold til idag\.")]
> public void SaErKnyttetInnIRefusjonsgruppeAAD_MedNULLOgNULLGittSomAntallDagerIForholdTilIdag_(int p0, int p1, int p2, int p3, int p4)

I got the same error when trying to run the test from the built in
Visual Studio 2013 Test Explorer, so this probably doesn't have anything
to do with ReSharper...?

But what can suddenly make specflow decide that "A06AD65_1" should be
matched as "A(.*)AD(.*)_(.*)"...?

Sam Holder

unread,
Nov 16, 2016, 8:52:55 AM11/16/16
to specflow
specflows template generation stuff lies to find things it thinks are variables, it treats numbers as potential variables. If they are not, then you'll need to edit the generated template to match what you have. I'd suggest tweaking the regex outside of specflow to make sure it does what you want first (with something like nregex.com) and ensure it captures the variables your step needs successfully

Sam Holder

unread,
Nov 16, 2016, 8:53:19 AM11/16/16
to specflow
its definitely nothing to do with resharper

Steinar Bang

unread,
Nov 16, 2016, 8:57:18 AM11/16/16
to spec...@googlegroups.com
>>>>> Sam Holder <samh...@gmail.com>:

> Which version of the specflow nuget package are you using?

From the packages.config of the project:
<package id="SpecFlow" version="2.1.0" targetFramework="net40" />
<package id="SpecFlow.NUnit" version="2.1.0" targetFramework="net40" />
<package id="SpecFlow.NUnit.Runners" version="2.1.0" targetFramework="net40" />

> are you using a step which calls other steps?

Not sure what that means, but if you're asking if my code behind calls a
different method that has a specflow attribute on it, then the answer is
no.

The full code of the step and the methods it calls, is:
[Then(@"(.*) er knyttet inn i expectedRefusjonsgruppe ([a-zA-Z][a-zA-Z0-9#._-]+) med (.*), (.*) og (.*) gitt som antall dager i forhold til idag\.")]
public void ThenErKnyttetInnIRefusjonsgruppeMedNULLOgNULLGittSomAntallDagerIForholdTilIdag_(string varenummer, string refusjonsgruppe, string fraDato, string forskrivesTilDato, string utleveresTilDato)
{
var pakningId = FindPakningFromVarenummer(varenummer);
var refusjonService = ServiceCreator.GetRefusjonService();
var refusjonDataset = refusjonService.GetRefusjonområdeListByPakning_ID(pakningId.Value, KodeverkLookupHelper.GetKodeverkLookup(), true);
Assert.AreNotEqual(0, refusjonDataset.Count, "No refusjonsområde found for varenummer " + varenummer);
var firstRefusjonsomradeFound = refusjonDataset[0];
var firstRefusjonsomradeFoundRow = firstRefusjonsomradeFound.TypedRow;
var pakningRefusjonsomradeRows = firstRefusjonsomradeFoundRow.GetPakningRefusjonsområdeRows();
var firstPakningRefusjonsomrade = pakningRefusjonsomradeRows[0];
var expectedFradato = DateTime.Today.AddDays(Double.Parse(fraDato));
var expectedForskrivesTilDato = ParseDate(forskrivesTilDato);
var expectedUtleveresTilDato = ParseDate(utleveresTilDato);
bool foundMatchingRefusjonsGruppe = CheckForMatchingRefusjonsgruppe(pakningRefusjonsomradeRows, refusjonsgruppe, expectedFradato, expectedForskrivesTilDato, expectedUtleveresTilDato);
Assert.IsTrue(foundMatchingRefusjonsGruppe, "Fant ingen expectedRefusjonsgruppe tilknyttet varenummer " + varenummer + " med refusjonsgruppekode " + refusjonsgruppe + " med FraDato " + expectedFradato + ", ForskrivesTilDato " + expectedForskrivesTilDato + " og UtleveresTilDato " + utleveresTilDato);
}

private bool CheckForMatchingRefusjonsgruppe(RefusjonDataset.PakningRefusjonsområdeRow[] pakningRefusjonsomradeRows, string expectedRefusjonsgruppe, DateTime? expectedFradato, DateTime? expectedForskrivesTilDato, DateTime? expectedUtleveresTilDato)
{
foreach (var pakningRefusjonsomrade in pakningRefusjonsomradeRows)
{
var actualRefusjonsgruppe = pakningRefusjonsomrade.RefusjonsområdeRow.RefusjonsgruppeKode;
var actualFraDato = pakningRefusjonsomrade.FraDato.Date;
var actualForskrivesTilDato = FindNullableForskrivesTilDato(pakningRefusjonsomrade);
var actualUtleveresTilDato = FindNullableUtleveresTilDato(pakningRefusjonsomrade);

if (expectedRefusjonsgruppe.Equals(actualRefusjonsgruppe) &&
Nullable.Compare(expectedFradato, actualFraDato) == 0 &&
Nullable.Compare(expectedForskrivesTilDato, actualForskrivesTilDato) == 0 &&
Nullable.Compare(expectedUtleveresTilDato, actualUtleveresTilDato) == 0)
{
return true;
}
}

return false;
}

private static DateTime? ParseDate(string date)
{
if (string.IsNullOrWhiteSpace(date) || "null".Equals(date.ToLower()))
{
return null;
}

return DateTime.Today.AddDays(Double.Parse(date));
}

private DateTime? FindNullableForskrivesTilDato(RefusjonDataset.PakningRefusjonsområdeRow firstPakningRefusjonsomradeRowFound)
{
try
{
return firstPakningRefusjonsomradeRowFound.ForskrivesTilDato.Date;
}
catch (StrongTypingException ste)
{
return null;
}
}

private DateTime? FindNullableUtleveresTilDato(RefusjonDataset.PakningRefusjonsområdeRow firstPakningRefusjonsomrade)
{
try
{
return firstPakningRefusjonsomrade.UtleveresTilDato.Date;
}
catch (StrongTypingException ste)
{
return null;
}
}


> does this step which calls other steps finish with a different step type
> (ie a when or a given)?

No.

There are other "Then"-steps in the same feature that calls the same
code to do the verification, but they don't call other methods with
specflow attributes.

Steinar Bang

unread,
Nov 16, 2016, 9:03:24 AM11/16/16
to spec...@googlegroups.com
>>>>> Sam Holder <samh...@gmail.com>:

> specflows template generation stuff lies to find things it thinks are
> variables, it treats numbers as potential variables. If they are not, then
> you'll need to edit the generated template to match what you have. I'd
> suggest tweaking the regex outside of specflow to make sure it does what
> you want first (with something like nregex.com) and ensure it captures the
> variables your step needs successfully

Ok, so what you're saying, is that there is something in this
[Then(@"(.*) er knyttet inn i expectedRefusjonsgruppe ([a-zA-Z][a-zA-Z0-9#._-]+) med (.*), (.*) og (.*) gitt som antall dager i forhold til idag\.")]
that no longer matches this
Og <varenummer> er knyttet inn i refusjonsgruppe <RefGruppe> med <FradatoRefusjon>, <ForskrivesTilDato> og <UtleveresTildato> gitt som antall dager i forhold til idag.
and that the error message with the generated template isn't something I
should be looking too closely at...?

And pasting in the code above I spotted the difference:
"expectedRefusjonsgruppe" where it should have been "refusjonsgruppe"

I renamed a variable with F2 (ReSharper command) and it looks like it
was a bit greedy in its renaming.

Thanks!


- Steinar

Steinar Bang

unread,
Nov 16, 2016, 9:21:19 AM11/16/16
to spec...@googlegroups.com
>>>>> Steinar Bang <s...@dod.no>:

> Ok, so what you're saying, is that there is something in this
> [Then(@"(.*) er knyttet inn i expectedRefusjonsgruppe ([a-zA-Z][a-zA-Z0-9#._-]+) med (.*), (.*) og (.*) gitt som antall dager i forhold til idag\.")]
> that no longer matches this
> Og <varenummer> er knyttet inn i refusjonsgruppe <RefGruppe> med <FradatoRefusjon>, <ForskrivesTilDato> og <UtleveresTildato> gitt som antall dager i forhold til idag.
> and that the error message with the generated template isn't something I
> should be looking too closely at...?

> And pasting in the code above I spotted the difference:
> "expectedRefusjonsgruppe" where it should have been "refusjonsgruppe"

Just for the record: when I replaced "expectedRefusjonsgruppe" in the
Then argument with "refusjonsgruppe", the test stopped failing because
it couldn't find the step.

Reply all
Reply to author
Forward
0 new messages