When using the TestCaseSource attribute in nunit ncrunch does not always detect all the cases.
All the cases are detected with visual studio test runner.
And ideas or is this a bug?
Thank in advance
Remco NCrunch Developer
#5032
10 Jan 2014 11:05 UTC
Hi, thanks for posting!
Check that the generated tests each have a unique name. If this is found to be the case, It'd be great to learn more about how these tests are structured (and named) for me to help identify whether there are problems involved with how NCrunch is handling them.
Cheers,
Remco
Check that the generated tests each have a unique name. If this is found to be the case, It'd be great to learn more about how these tests are structured (and named) for me to help identify whether there are problems involved with how NCrunch is handling them.
Cheers,
Remco
this my code
namespace XMLDataExtractorTests
{
[TestFixture]
internal class XMLRetrieverTests
{
public static List<object[]> _metricCases = new List<Object[]>
{
new object[]
{
TestUtilities.Metrics[ 0 ], ApplicationMetricsFile, ApplicationMetricsSql
},
new object[]
{
TestUtilities.Metrics[ 1 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 2 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 3 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 4 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 5 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 6 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 7 ], RuleResultFile, CodeRuleResultSql
}
};
[TestCaseSource( "_metricCases")]
public void GetXmlDocument_GivenMetric_ReturnsXDocumentContainingMetric( Metric metric, string filePath, string sql )
{
......
}
[TestCaseSource( "_metricCases" )]
public void GetXmlDocument_GivenMetric_CallsCorrectMethodWithCorrectSqlInSqlHelperWrapper( Metric metric, string filePath, string sql )
{
....
}
}
}
so it only runs the first few test cases but using the visual studio test runner it works fine.
Thanks in advance
namespace XMLDataExtractorTests
{
[TestFixture]
internal class XMLRetrieverTests
{
public static List<object[]> _metricCases = new List<Object[]>
{
new object[]
{
TestUtilities.Metrics[ 0 ], ApplicationMetricsFile, ApplicationMetricsSql
},
new object[]
{
TestUtilities.Metrics[ 1 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 2 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 3 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 4 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 5 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 6 ], RuleResultFile, CodeRuleResultSql
},
new object[]
{
TestUtilities.Metrics[ 7 ], RuleResultFile, CodeRuleResultSql
}
};
[TestCaseSource( "_metricCases")]
public void GetXmlDocument_GivenMetric_ReturnsXDocumentContainingMetric( Metric metric, string filePath, string sql )
{
......
}
[TestCaseSource( "_metricCases" )]
public void GetXmlDocument_GivenMetric_CallsCorrectMethodWithCorrectSqlInSqlHelperWrapper( Metric metric, string filePath, string sql )
{
....
}
}
}
so it only runs the first few test cases but using the visual studio test runner it works fine.
Thanks in advance
Remco NCrunch Developer
#5039
10 Jan 2014 23:32 UTC
Hi, thanks for sharing the code. Something I just thought I'd check with you here is whether the .ToString() method on the Metric class returns a unique value for each Metric object.
For NCrunch this is particularly important, as TestCaseSource relies on .ToString() to generate the name of each test it returns. NCrunch relies on each test having a unique name in order for the test to be correctly identified through the engine.
I noticed when testing this code that when I didn't override the .ToString() method on the Metric class and provide something unique, NCrunch would only run 2 tests per TestCaseSource attribute, where it should normally be running 8.
Does this solve the issue for you?
Cheers,
Remco
For NCrunch this is particularly important, as TestCaseSource relies on .ToString() to generate the name of each test it returns. NCrunch relies on each test having a unique name in order for the test to be correctly identified through the engine.
I noticed when testing this code that when I didn't override the .ToString() method on the Metric class and provide something unique, NCrunch would only run 2 tests per TestCaseSource attribute, where it should normally be running 8.
Does this solve the issue for you?
Cheers,
Remco
Post a reply
Log in to reply.