为什么Intellitest试图为私有只读字典字段创建IEqualityComparers? [英] Why is Intellitest attempting to create IEqualityComparers for a private readonly Dictionary field?

查看:57
本文介绍了为什么Intellitest试图为私有只读字典字段创建IEqualityComparers?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


从我的


真诚地,


奥斯卡


Shamelessly pasting from my unanswered SO question.

I created an empty class library project containing only this class.

public class DictionaryDemo
{
    private readonly Dictionary<string, int> dictionary = new Dictionary<string, int>();

    public void Add(string key, int value)
    {
        this.dictionary.Add(key, value);
    }
}

From this class I generated a test project with Intellitest. Apart from making a few formatting edits to tidy for posting here, I made no edits to this test project. This contains only the following Intellitest test.

[PexClass(typeof(DictionaryDemo)), TestClass]
public partial class DictionaryDemoTest
{
    [PexMethod]
    public void AddTest([PexAssumeUnderTest] DictionaryDemo target, string key, int value)
    {
        target.Add(key, value);
    }
}

When I run the Intellitest method I get the following results.

The actual generated tests themselves seem reasonable ish. I'm not sure if the low coverage indicates that more tests should be generated to cover the complexities of the dictionary, or if that stems from the issues below.

My concern stems from the warnings. I do not understand why Intellitest would be attempting to create instances of these types. I initially assumed Intellitest was trying to set the dictionary field and using these instances to instantiate a new Dictionary. This was undesired behaviour, so I added the [PexExplorableFromConstructor(typeof(DictionaryDemo))] attribute which should (I believe) prevent any direct setting of private fields, but apart from the warning about guessing how to create DictionaryDemo disappearing, the results were identical.

It's worth noting that many of the types that it's attempting to create here are not even accessible.

So the question is basically, what's happening here? Is this intended behaviour for Intellitest? If this is Intellitest trying to set the dictionary field, that is unwanted behaviour. How do I stop it, and why doesn't the [PexExplorableFromConstructor] stop it? If that's not what's happening, why is it trying to use all of these types?


Additional stuff I've already tried

I've played about with a bunch of the PexCreatable... and PexExplorable... attributes without success, including [PexCreatableByConstructor(typeof(DictionaryDemo), MaySetRemainingFieldsByReflection = false)] which seems like it should explicitly disallow the setting of the field.

I've tried creating a factory for DictionaryDemo with the same result.

I've tried adding a [PexExplorableFromConstructor(typeof(Dictionary<string, int>))] but this has also had no effect.

This behaviour appears to be identical between VS 2015 and VS 2017 RC.

解决方案

Hi TheOtherSamP,

I could repro your issue in my side, and I have read a MSDN document with the following link, then I could disable the waring with the following screenshot:

Then this warning was disappeared, please refer to the following screenshot:

https://msdn.microsoft.com/en-us/library/dn823749.aspx?f=255&MSPPError=-2147217396

Sincerely,

Oscar


这篇关于为什么Intellitest试图为私有只读字典字段创建IEqualityComparers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆