<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy" -->

---
title: Verifying code and testing with Pex | daily.dev
description: A walkthrough of Microsoft Research's Pex tool, an automated white-box testing tool for .NET that explores code execution paths using a constraint solver to...
canonical: https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Verifying code and testing with Pex | daily.dev
og:description: A walkthrough of Microsoft Research's Pex tool, an automated white-box testing tool for .NET that explores code execution paths using a constraint solver to...
og:url: https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy
og:image: https://api.daily.dev/og/posts/SYpbKuEfy.png
og:image:alt: Verifying code and testing with Pex
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Verifying code and testing with Pex

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 4 min read · 0 upvotes · 0 comments

## Summary

A walkthrough of Microsoft Research's Pex tool, an automated white-box testing tool for .NET that explores code execution paths using a constraint solver to generate unit tests. The author tests Pex against a hand-written string extension method (mimicking VB6's Left function), and Pex uncovers two unhandled edge cases that throw uncaught exceptions. The post shows how Pex's 'Add precondition' feature helps fix the code by adding proper argument validation, and notes that explorations can also be saved as unit tests integrated with Visual Studio Team Test.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2009-01-06-verifying-code-and-testing-with-pex>

## Questions this post answers

### What is Pex and how does it do automated testing for .NET code?

Pex is an automated white-box testing tool from Microsoft Research for .NET that systematically explores every reachable branch in a program by monitoring execution traces and using a constraint solver to generate new test cases with different behavior. It works on any existing .NET assembly without a pre-existing test suite, can be guided by parameterized unit tests, and produces small test suites with high code and assertion coverage. Generated tests integrate with Visual Studio Team Test and other frameworks.

_Developers evaluating automated test-generation tools can compare options like Pex through daily.dev._

### Why does calling Substring(0, length) on a string throw an exception for certain inputs?

Calling Substring(0, 2) on an empty string throws an uncaught ArgumentOutOfRangeException because the requested length exceeds the string's actual length. A naive implementation of a VB6-style Left method that only checks for negative length values misses this edge case, since .NET's Substring throws when the length argument exceeds the available characters in the source string.

_Developers debugging string-handling edge cases can track testing techniques like this via daily.dev._

## Similar posts on daily.dev

- [New Microsoft tool lets devs spin up AI behavior tests using text descriptions](https://daily.dev/posts/new-microsoft-tool-lets-devs-spin-up-ai-behavior-tests-using-text-descriptions-c6lh1ot4i) · TechCrunch · 1 upvotes · 0 comments
- [Does your code match your spec?](https://daily.dev/posts/does-your-code-match-your-spec--beehfvwqo) · Kiro · 0 upvotes · 0 comments
- [To be a better programmer, write little proofs in your head](https://daily.dev/posts/to-be-a-better-programmer-write-little-proofs-in-your-head-zolbsglo8) · Lobsters · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#visual-studio](https://daily.dev/tags/visual-studio)

[View this post on daily.dev](https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Verifying code and testing with Pex","url":"https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy"},"datePublished":"2026-10-04T13:05:29.138Z","dateModified":"2026-10-04T13:08:04.583Z","description":"A walkthrough of Microsoft Research's Pex tool, an automated white-box testing tool for .NET that explores code execution paths using a constraint solver to...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d9311211811aca4783e01441115127cf?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d9311211811aca4783e01441115127cf?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,visual-studio","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"Verifying code and testing with Pex"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/verifying-code-and-testing-with-pex-sypbkuefy#faq","mainEntity":[{"@type":"Question","name":"What is Pex and how does it do automated testing for .NET code?","acceptedAnswer":{"@type":"Answer","text":"Pex is an automated white-box testing tool from Microsoft Research for .NET that systematically explores every reachable branch in a program by monitoring execution traces and using a constraint solver to generate new test cases with different behavior. It works on any existing .NET assembly without a pre-existing test suite, can be guided by parameterized unit tests, and produces small test suites with high code and assertion coverage. Generated tests integrate with Visual Studio Team Test and other frameworks. Developers evaluating automated test-generation tools can compare options like Pex through daily.dev."}},{"@type":"Question","name":"Why does calling Substring(0, length) on a string throw an exception for certain inputs?","acceptedAnswer":{"@type":"Answer","text":"Calling Substring(0, 2) on an empty string throws an uncaught ArgumentOutOfRangeException because the requested length exceeds the string's actual length. A naive implementation of a VB6-style Left method that only checks for negative length values misses this edge case, since .NET's Substring throws when the length argument exceeds the available characters in the source string. Developers debugging string-handling edge cases can track testing techniques like this via daily.dev."}}]}
```

