DevLabs > DevLabs Forums > Pex > Exploratiation Error in Pex v0.16 with classes with multiple constructors ?
Ask a questionAsk a question
 

AnswerExploratiation Error in Pex v0.16 with classes with multiple constructors ?

  • Monday, September 21, 2009 11:02 PMAlexander Wurzinger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Tuesday, September 22, 2009 1:06 AMNikolai TillmannMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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
  • Tuesday, October 27, 2009 1:41 PMNikolai TillmannMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

All Replies

  • Tuesday, September 22, 2009 1:06 AMNikolai TillmannMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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
  • Tuesday, October 27, 2009 1:41 PMNikolai TillmannMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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