locked
Why does Pex try to create a new test project? RRS feed

  • Question

  • If I already have a test project for an assembly, why does Pex keep trying to create a new one when I click "Save Test..."?

    It also seems to be failing at adding the reference to Microsoft.Pex.Framework. Is there any way I can configure the individual steps when saving a test?

    Thanks,
    Flora
    Monday, November 10, 2008 11:32 PM

Answers

  • Not really. Ok, just to make sure: what is the VS version you are running? which version of Pex did you install? Could you list the Pex assemblies in the gac (by running gacutil /l | findstr Pex from a VS command prompt).

    Meanwhile, as a workaround, you should be able to run the wizard from the command line, then simply open the generated project.

        pexwizard.exe AssemblyUnderTest.dll

    It does not rely on any VS API so this should word.


    Jonathan de Halleux
    Tuesday, November 11, 2008 4:52 AM

All replies

  • In order for Pex to pick up a project, the following must be met:

    - the test project must reference the project under test,
    - the test project must reference Microsoft.Pex.Framework.dll (you can add it manually through Add References -> .Net -> ...)
    - the test project must reference Team Test assembly,
    - there must be an assembly level attribute PexAssemblyUnderTest with the project under test in the test project:

    // PexAssemblyInfo.cs in the test project  
    // ProjectUnderTestAssemblyName is the project under test *assembly* name  
    [assembly:PexAssemblyUnderTest("ProjectUnderTestAssemblyName")]  
     

    Could you tell us more about failing to add the Microsoft.Pex.Framework reference? Do you have steps to repro?
    Jonathan de Halleux
    Tuesday, November 11, 2008 12:05 AM
  • I checked and added all the criteria and Pex still can't seem to find the test project. By Test Team assembly do you mean the unit test framework assembly?

    I just installed Pex today and opened up one of our projects, found one of our simple string manipulation methods to try it out on. I right-clicked on the method to run Pex explorations, then selected one of the tests to save. It just keeps failing at the step to add the Pex framework reference (step 8). Is there something else I need to do first?

    Thanks,
    Flora
    Tuesday, November 11, 2008 1:17 AM
  • Hi Flora,

    When the code update fails, it should show the dialog with the tree of steps. One of these steps should have a Red cross indicated that it failed. If you click on this item, it will display the message of the failure in the details text box? Could you send me that textbox?

    Here's another way to try: right click on the project under test, there should be a Pex submenu, then select 'Create Parameterized Unit Test Stubs'. This will run our wizard in a different fashion and hopefully work for you. Once the wizard has generated the new project, you can simply run that project or go back to your method and run it (pex should pick it up automatically).
    Jonathan de Halleux
    Tuesday, November 11, 2008 1:41 AM
  • The message isn't very informative:

    Update result:
    could not add reference to Microsoft.Pex.Framework


        Add reference 'Microsoft.Pex.Framework'

    Trying the 'Create Parameterized Unit Test Stubs' also fails at this step.

    Is there a log file or any way to enable more verbose logging?

    Thanks,
    Flora

    Tuesday, November 11, 2008 1:57 AM
  • Not really. Ok, just to make sure: what is the VS version you are running? which version of Pex did you install? Could you list the Pex assemblies in the gac (by running gacutil /l | findstr Pex from a VS command prompt).

    Meanwhile, as a workaround, you should be able to run the wizard from the command line, then simply open the generated project.

        pexwizard.exe AssemblyUnderTest.dll

    It does not rely on any VS API so this should word.


    Jonathan de Halleux
    Tuesday, November 11, 2008 4:52 AM
  • I am having a simular intermitent problem.  I am using the Enterprise version.  I am also using VS 2008 Team Developer edition.  When I rerun Pex and go to save my tests, It try's to create a new project.  Pex assembly under test is configuried correctly.  Some times this works ok, but then it seem's to stop.

    Thanks.

    Friday, May 1, 2009 2:39 PM
  • I think I know what the problem is.  I changed the code in the .g.cs because it was having an ambiguity broblem with the Screen object.  When I fix the ambiguity problem, the next run through it try's to recreate the code again before it changed.  But if I don't try and fix the error, then it tries to create another project file on the next run.
    Friday, May 1, 2009 6:03 PM
  • Haha that might explains things: the generated test has some compilation errors which means this project does not build. Thus, Pex cannot reflect over it to figure out if it is the test project it should. As a result, it creates a new project. I'll look at this issue for the next release.

    Meanwhile, never edit the .g.cs file! I'm not kidding Pex will modify them without notice. If you have a name clashing issue, go to Tools -> Options -> Pex -> General  and set NamespaceMode to Unique. Pex will emit fully qualified type names.

    Cheers,
    Peli
    Jonathan "Peli" de Halleux
    Friday, May 1, 2009 8:08 PM