Unit test serialization error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Unit test serialization error

  1. #1
    Join Date
    Feb 2011
    Posts
    5

    Unit test serialization error

    Ok so I have the following code as my unit test:


    namespace MusicTest
    {
    [TestClass]
    public class MusicGig
    {

    [TestMethod]
    public static Stream Serialize(object source)
    {
    IFormatter formatter = new BinaryFormatter();
    Stream stream = new MemoryStream();
    formatter.Serialize(stream, source);
    return stream;
    }
    }
    }

    however when I try and run the test I get the following error..

    UTA007: Method Serialize defined in class MusicTest.MusicGig does not have correct signature. Test method marked with the [TestMethod] attribute must be non-static, public, does not return a value and should not take any parameter. for example: public void Test.Class1.Test().

    It has me confused, is it just a simple code error somewhere?

    Thanks in advance

  2. #2
    Join Date
    Dec 2008
    Posts
    144

    Re: Unit test serialization error

    Your example code doesn't show this, which is why I'm asking: You do know that you have to mark all classes to be serialized, right? If you don't tag the class as serializable then your call to serialize will automatically be invalid.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,219

    Re: Unit test serialization error

    The error message is very clear:

    Test method marked with the [TestMethod] attribute must be non-static, public, does not return a value and should not take any parameter. for example: public void Test.Class1.Test().
    It's telling you that any method marked with the [TestMethod] attribute must be a public static void method.

    Your method of "public static Stream Serialize( ... )" that you've marked with the [TestMethod] attribute isn't a public static void method. If you need this method signature, remove the [TestMethod] attribute (but don't expect the method to be run as part of the test suite).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center