Trouble with Custom PropertyAttribute - SerializationException with enum parameter
"Walker Jay W" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <EB576B995DA9DF4894A78EE7450C0E0C01F5C295@AUS0010CP3MB02.ds.irsnet.gov> |
I'd like to take advantage of derived PropertyAttributes to support
Requirement Traceability in our unit tests based on the examples at:
http://nunit.net/index.php?p=property&r=2.4.3
<http://nunit.net/index.php?p=property&r=2.4.3>
If I use the [Property(string, object)] syntax where object is a system
type such as string or int, I am able to execute the tests.
EX: [Property("Traceability", "Requirement1")]
However, my preference is to define a custom attribute to take advantage
of compile time type checking:
EX: [Traceability(Requirements.Requirement1)]
where Requirements is a public enum
When I attempt to execute the tests by loading the test assembly in the
nunit gui (nunit.exe v 2.4.3), I receive the following error:
System.Runtime.Serialization.SerializationException: Unable to find
assembly 'PropertyTest, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=0ff96b337bb1c2da'
Here is a partial stack trace:
System.Runtime.Serialization.SerializationException...
Server stack trace:
at
System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAss
embly()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(Bina
ryAssemblyInfo assemblyInfo, String name)
...
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at NUnit.Core.TestRunner.get_Test()
at NUnit.Util.ProxyTestRunner.get_Test()
at NUnit.Util.TestLoader.LoadTest(String testName)
I only receive the error when the CustomAttribute takes an enum
parameter (similar to the Priority example). If the CustomAttribute
takes an int parameter, it runs fine. I noticed in the nunit source,
there are no tests using CustomAttributes with an enum parameter,
although the website example shows this as a valid case. I assume there
is a subtle error in my code.
Here is the source to reproduce the problem:
//begin
//referenced Nunit.framework.dll (v2.4.3).
//loaded into Nunit.exe (v2.4.3) with Load Project and pointed directly
to the PropertyTest.dll assembly
//at which time I received the exception before executing any tests.
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace PropertyTest
{
[TestFixture]
public class Class1
{
[Test]
[Property("Severity", "Critical")]
public void SimplePropertyTest()
{ /* ... */ }
[Test]
[Traceability(Requirements.Requirement1)]
public void CustomPropertySingleTest()
{ /*...*/ }
[Test]
[Traceability(Requirements.Requirement2)]
[Traceability(Requirements.Requirement3)]
public void CustomPropertyMultipleTest()
{ /*...*/ }
}
public enum Requirements
{
Requirement1,
Requirement2,
Requirement3,
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class TraceabilityAttribute : PropertyAttribute
{
public TraceabilityAttribute(Requirements level)
: base(level)
{
}
}
}
//end
Any help would be appreciated,
Thanks,
Jay
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4