Rank: Newbie
Groups: Registered
Joined: 4/2/2015(UTC) Posts: 2 Location: Netherlands
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
I'm getting the following failure on my tests projects when using nCrunch. My bet is that it is related MyTestCategoryAttribute. We have extended the TestCategoryBaseAttribute with a custom TestCategoryAttribute that takes enum values. Let's not discuss why we are using that, but that's just the way it is. Anyway, i think that is causing issues when nCrunch, for some reason, wants to analyze the attribute. Normally the TestCategoryAttribute takes a list of strings as parameters, but now it takes a list of enum values (which are represented as Ints), which causes this cast to fail?! Here is an example of the code Code:
public class MyTestCategoryAttribute : TestCategoryBaseAttribute
{
private List<string> testcategories = new List<string>();
public MyTestCategoryAttribute(params TestCategory[] categories)
{
foreach (var category in categories)
{
this.testcategories.Add(category.ToString());
}
}
public override IList<string> TestCategories
{
get { return this.testcategories; }
}
}
Which is used like this Code:
[TestMethod]
[Description("Validates the attributes on the test methods.")]
[MyTestCategory(TestCategory.Something, TestCategory.ContinuousIntegration)]
public void ValidateAttributes()
{
ValidateTestAttributesTest.TestValidateTestAttributes(this.TestContext);
}
Do you agree, or could it be something else that is causing this? Should we wait for a new release of ncrunch of is there a workaround? EDIT: After looking at the nCrunch code using Reflector i'm pretty sure that this above mentioned code is causing the problem. I think nCrunch.Module.MSTest.Integration.MSTestFramework.getCategoryValue(ReflectedAttribute attribute) is hitting the last return statement Code:
return new string[] { ((string) attribute2.ConstructorParameters[0].Value) };
and will fail because the parameter is an Enumerable/Int and not a string. Beter would be to call ToString() on .Value Thanks! Code:
NCrunch: If you are experiencing problems in getting this project to build, have a look at http://www.ncrunch.net/documentation/troubleshooting_project-build-issues
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.
at nCrunch.Module.MSTest.Integration.MSTestFramework.getCategoryValue(ReflectedAttribute attribute)
at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at nCrunch.Reflection.ReflectedMember.GetValuesFromNamedAttributes[T](String[] attributeTypeNames, Func`2 getValueFunc)
at nCrunch.Module.MSTest.Integration.MSTestFramework.resolveCategories(ReflectedMethod method)
at nCrunch.Module.MSTest.Integration.MSTestFramework.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName)
at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, TestFrameworkDescription[] frameworks, ComponentUniqueName testComponentUniqueName)
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.DiscoverTests(TestFrameworkDescription[] applicableTestFrameworks, ComponentUniqueName testComponentUniqueName)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)
|