DevLabs >
DevLabs Forums
>
Pex
>
Exploratiation Error in Pex v0.16 with classes with multiple constructors ?
Exploratiation Error in Pex v0.16 with classes with multiple constructors ?
- Hi,
I noticed, that if you let PEX explore a Class which has two Constructors, one without parameters, and one with parameters, Pex will always try to use the one with Parameters.
This even happens, if Pex fails to create the Object with the parameter Constructor, but succeeds with the parameter les one.
Well this seems like a bug to me, I think Pex should at last try to use the Parameter less one, even If you don't give it a factory.
Answers
- Indeed, the current version of Pex would pick one particular way to create an instance, and then stick to it, even if it turns out to be unproductive.
We should change that in the future; for now, the only workaround is that you Accept/Edit the suggested factory method, and let it call an easier method.
Btw: The current algorithm to pick a way to create an instance works basically as follows:
- It picks a constructor which (transitively) calls the least number of other methods/constructors, while assigning values to as many fields as possible.
- For all non-public fields not assigned by the chosen constructor, Pex would try to find "setter" methods that set those fields.
Nikolai Tillmann- Proposed As Answer byNikolai TillmannMSFT, OwnerTuesday, September 22, 2009 1:44 AM
- Marked As Answer byPeliMSFT, OwnerSaturday, November 07, 2009 9:15 AM
In recent versions of Pex, you may declare multiple object factory methods for the same type. Pex will then try all of them.
(However, when Pex is guessing, Pex will stick to one of them, so it is up to you to create multiple factory methods.)
Nikolai Tillmann - Tell us how you use Pex- Marked As Answer byPeliMSFT, OwnerSaturday, November 07, 2009 9:15 AM
- Proposed As Answer byNikolai TillmannMSFT, OwnerTuesday, October 27, 2009 1:41 PM
All Replies
- Indeed, the current version of Pex would pick one particular way to create an instance, and then stick to it, even if it turns out to be unproductive.
We should change that in the future; for now, the only workaround is that you Accept/Edit the suggested factory method, and let it call an easier method.
Btw: The current algorithm to pick a way to create an instance works basically as follows:
- It picks a constructor which (transitively) calls the least number of other methods/constructors, while assigning values to as many fields as possible.
- For all non-public fields not assigned by the chosen constructor, Pex would try to find "setter" methods that set those fields.
Nikolai Tillmann- Proposed As Answer byNikolai TillmannMSFT, OwnerTuesday, September 22, 2009 1:44 AM
- Marked As Answer byPeliMSFT, OwnerSaturday, November 07, 2009 9:15 AM
In recent versions of Pex, you may declare multiple object factory methods for the same type. Pex will then try all of them.
(However, when Pex is guessing, Pex will stick to one of them, so it is up to you to create multiple factory methods.)
Nikolai Tillmann - Tell us how you use Pex- Marked As Answer byPeliMSFT, OwnerSaturday, November 07, 2009 9:15 AM
- Proposed As Answer byNikolai TillmannMSFT, OwnerTuesday, October 27, 2009 1:41 PM


