5

I love the idea of Pex - autogenerating unit tests through static code analysis - but the tests that are actually generated by the tool are horrible, ugly, tightly coupled to Pex modules, difficult to read and understand etc.

Is a tool like that really suitable (in its current state) for use in an enterprise environment, where the emphasis must be on ease of maintenance?

Or have I misunderstood the intended use of Pex?

MalcomTucker
  • 7,407
  • 14
  • 72
  • 93

4 Answers4

1

Indeed, you have misunderstood the intended use.

Pex is a white-box testing tool. It generates test cases based on the analysis of the code it should test. The reason for this is to detect and test edge cases. So basically, you shouldn't even change the auto-generated tests.

Your normal unit-tests can't be replaced by Pex. It's just an additional tool.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
1

This seems a subjective question...

I'd say that yes, tests written in a given framework/API are often tightly coupled to that framework. Pex's intention is not to generate "readable" tests, it's to ensure code coverage for a given set of constraints. If that's valuable to your product, then it's suitable - and certainly I'd wager that for a given team and a given codebase, this will provide value.

Every enterprise is different, but it's the product and its code that dictates the suitability of a testing tool. I would suggest that the thing to question is the value of Pex for a given codebase, regardless of the organisation in question.

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
1

I have used pex in a large financial institution and would recommend its use, but only for a very specific case. I think pex is good at what it does (as described elsewhere here, white box tests to find edge cases), but the tests do not have significant longevity as they are very tightly coupled.

Basically pex is great at generating coverage. If you have no tests and want some fast, use Pex. BUT THEN I recommend that instead of using it again you enforce standards for new code to meet an agreed coverage metric with hand written tests.

In this way the fragile tests from pex get replaced over time with tests that are more flexible and of a higher quality.

AlSki
  • 6,868
  • 1
  • 26
  • 39
0

Pex is very useful for testing complex algorithms that do not rely on anything external. For example, it will not help you find edge cases in SQL statements or file access. However, for finding edge cases and increasing code coverage, it is extremely useful in addition to your normal unit tests.

akton
  • 14,148
  • 3
  • 43
  • 47