locked
Pex tests generator truncates long test names.

    Question

  • I usually have tests with quite long names where I specify a test case and expected result. If my test is a PUT, Pex generates necessary unit tests, but it might truncate the original name.

    For instance, I have an unit test named with 90 characters (I like typing =).
    Pex truncates the name to 40 characters and add an ordered number. Is there a reason for that?

    I want to have the full original name in the generated tests. Is it possible to specify it somewhere?

    Thanks.
    Sunday, October 18, 2009 12:27 PM

Answers

  • The reason is long file name. When Pex saves the generate test, it uses the method name to create the file name.  To avoid hitting issues with long file name, we trim the method name if it gets tool long.

    There multiple ways to work around this:

    1) set the 'pex_max_metadata_name_length' environment variable to a large integer value. This might create issues since Pex might create large metadata names.

    2) implement your own test naming logic by implementing a IPexTestNamer interface. To do so, implement the PexTestNamerAttributeBase and apply this attribute on your test assembly. Read this document on how to write Pex extensions http://research.microsoft.com/en-us/projects/pex/guidancepexextensions.pdf.

    Jonathan "Peli" de Halleux - Give us your input about Pex!
    Sunday, October 18, 2009 3:14 PM
    Owner

All replies

  • The reason is long file name. When Pex saves the generate test, it uses the method name to create the file name.  To avoid hitting issues with long file name, we trim the method name if it gets tool long.

    There multiple ways to work around this:

    1) set the 'pex_max_metadata_name_length' environment variable to a large integer value. This might create issues since Pex might create large metadata names.

    2) implement your own test naming logic by implementing a IPexTestNamer interface. To do so, implement the PexTestNamerAttributeBase and apply this attribute on your test assembly. Read this document on how to write Pex extensions http://research.microsoft.com/en-us/projects/pex/guidancepexextensions.pdf.

    Jonathan "Peli" de Halleux - Give us your input about Pex!
    Sunday, October 18, 2009 3:14 PM
    Owner
  • Thanks, Peli! It helps.

    I implemented IPexTestNamer and PexTestNamerAttributeBase as you suggested and now I have tests names as I want. I also wrote a small post based on my experience.

    By the way, do you plan to put more information into GuidancePexExtensions.pdf?
    Monday, October 19, 2009 9:09 PM
  • I've added a link to your post on our home page. We have no immediate plans on improving this document.
    Jonathan "Peli" de Halleux - Give us your input about Pex!
    Monday, October 19, 2009 11:56 PM
    Owner
  • > By the way, do you plan to put more information into GuidancePexExtensions.pdf?

    As Peli said, we don't have immediate plans of our own.
    If you need need help when you want to extend Pex, drop us a note at pexdev@microsoft.com, and we might add a section to the document.

    Nikolai Tillmann - Tell us how you use Pex
    Tuesday, October 20, 2009 4:48 AM
    Owner