Задайте вопросЗадайте вопрос
 

ОтвеченоTesting with immutable structs

  • 18 ноября 2008 г. 18:14Judah Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    We use a lot of immutable structs in our code. We want Pex to test classes that consume immutable structs. But Pex has difficulty with this. Here's an example:

    public struct UserInfo
    {
    public UserInfo(string name, int id)
    : this()
    {
    this.Name = name;
    this.Id = id;
    }

    public string Name { get; private set; }
    public int Id { get; private set; }
    }

    And the consumer that we want to test with Pex:

    public class Consumer
    {
    public Consumer(UserInfo info)
    {
    ...
    }
    }

    Pex can't test consumer. It spits out a commented-out unit test:

            [Test]
            [Ignore("the body of the test was commented out as it might not be compilable")]
            [PexGeneratedBy(typeof(Consumer))]
            [PexNotCompilable]
            public void Constructor01()
            {
                /* 
                Consumer consumer;
                UserInfo userInformation = default(UserInfo);
                // cannot set UserInfo.<Name>k__BackingField: field is not visible
                userInformation.Name = "";
                consumer =
                  this.Constructor(s0, userInformation);
                // validation of result values is supported for primitive types only
                */
            }

    I don't care that Pex can't figure out the constructor logic. Just spit out a default UserInfo and move along. Why doesn't this work?

    Or better yet, have Pex figure out that it can use the constructor.

    This is a major blocker for us, as we use a lot of these immutable structs everywhere.

    Tech, life, family, faith: http://judahgabriel.blogspot.com
    •  

Ответы

Все ответы