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.