4 ms·
I tried it. Doesn't usually work all that well though, and basically only works on built in .Net types. If you pass in your own object containing only .Net type
by earlz 13y ago
I tried it. Doesn't usually work all that well though, and basically only works on built in .Net types. If you pass in your own object containing only .Net types, it's not smart enough to fill those in with potential test data. Interesting idea, but I found it completely worthless
- danbruc 13y agoI can not test it at the moment but you may have to do the object creation inside a wrapper method. public static void TestWrapper(String foo, Int32 bar, Boolean buzz, Decimal foobar) { var thing = new Thing(foo, bar); thing.Buzz = buzz; Test(thing, blah); } public static Test(Thing thing, Decimal foobar) { thing.DoStuff(); if (thing.State == 42) { thing.DoOtherStuff(foobar); } } In my experience Pex yields really great results when you use it to analyze methods that are close to mathematically functions with not to many side effects and especially state mutation. Tracking changing state over time and finding sequences of operations to prepare an object to a certain state and then checking the behavior of the object in this state is much harder than analyzing a (almost) pure function.
- georgefox 13y agoYou can test it online at pex4fun.com. Here are two tests, one using a function that takes built-in types as parameters and instantiates a Thing to operate on, and a second that takes a Thing input and operates on it directly. It seems to generate interesting cases for both, but it's much more easily readable with the more basic input types, as the parameters are easily displayed in the table. http://pex4fun.com/default.aspx?language=CSharp&code=OgPsvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee__997o7nU4n99%2f%2fP1xmZAFs9s5K2smeIYCqyB8%2ffnwfPyLWTbG8SF9fN22_OEyS1XpSFtN0WmZNk76Z03fJL05SelZ1cZm1edq0NV54VlXpL04v8vYwbfDPLwkaFcs2fZLVG1pMqqpMn6x%2f8INIG2koiDAKW9rpeVWNGPYkq_9wK8ENTzsvmjGw_gzNDsPPgctneEs_73ejHTytXrfr8%2fOtLvA6b9f1Mt26n97lcT1Od__kvweIMH5TfbVa5fXWnfSR%2fv28usLfN3b1ZTvPa_lvlk_LRVYC88jQTO%2fo_a62_UAUstZh8pJmocy3Xns0Plu29%2fZAr1H6hCYqz5bphFqN0qcbEb0kvFpMGBF7mV%2fp5DFEtCb2Mi251Zjn%2fzMG7X2nw32TN_0WtxuZ7sx4hsfCL3G3qb66GWPtS9Cxs59_Yj%2fxJqmDxC%2f5fwIAAP%2f%2f http://pex4fun.com/default.aspx?language=CSharp&code=OgP... http://pex4fun.com/default.aspx?language=CSharp&code=_QLsvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee__997o7nU4n99%2f%2fP1xmZAFs9s5K2smeIYCqyB8%2ffnwfPyLWTbG8SF9fN22_OEyS1XpSFtN0WmZNk76Z03fJL05SelZ1cZm1edq0NV54VlXpL04v8vYwbfDPLwkaFcs2fZLVG1pMqqpMn6x%2f8INIG2koiDAKW9rpeVWNGPYkq_9wK8ENTzsvmjGw_gzNDsPPgctneEs_73ejHTytXrfr8%2fOtLvA6b9f1Mt26n97lcT1Od__kvweIMH5TfbVa5fXWnfSR%2fv28usLfN3b1ZTvPa_lvlk_LRVYC88jQTO%2fo_a62_UAUstZh8pJmocy3mNJpO0qf0NTk2TKd0Oej9OlG1Noxz_Fn3NgRXTF_kzftFkHUdw06w6jwC4oI%2fr2pe_2H247t5KWf2E88GneQ_CX%2fTwAAAP%2f%2f http://pex4fun.com/default.aspx?language=CSharp&code=_QL...
- danbruc 13y agoNice. If you use the second variant you have to click an a test case to see which arguments have been passed to the constructor of Thing. Just from the tabular view most test cases look identical.
- romaniv 13y agoIt would be very, very useful if only it worked with regular expressions. Or if you could run it against F# functions.
- porges 13y agoRex is the equivalent of Pex (which is what this is based upon) for regular expressions: http://research.microsoft.com/en-us/projects/rex/ http://research.microsoft.com/en-us/projects/rex/
- danbruc 13y agoI just tested it using Pex for fun and - to my surprise - Pex was able to deal with regular expression and this AFAIK without any build-in knowledge of regular expressions. using System; using System.Text.RegularExpressions; public class Program { public static String Puzzle(String input) { if (new Regex("123(foo|bar){3}456[0-9]{5}789").IsMatch(input)) { throw new ArgumentException(); } else { return input; } } } Pex reported three test cases. null ArgumentNullException "" okay "123foobarbar45600000789bb" ArgumentException Try this example yourself. http://www.pexforfun.com/default.aspx?language=CSharp&code=HgHsvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee__997o7nU4n99%2f%2fP1xmZAFs9s5K2smeIYCqyB8%2ffnwfPyLWTbG8SF9fN22_OEz8v8Zv8nft_FV_sS6z_vTdqs6bpqiWzWGSrNaTspim0zJrmvRlXV3U2SL5xUma6hdNm7X043VbA9zL9Q9_UOZb_lexXK3bO9QW7dO0OE_3lvlVSv3k77Y_2t27t3VeVT8zyeo7v%2fjeL9m%2f%2f_n3drYffv8X3%2f8lDw4efnRnfNZ8kbXT_ZZAucMgBFCatvO6ukoB7Li_WC%2fyZXv6bpqvWkJ6684hN%2fol%2fG9eNnnwZp2363opqLmGvyT5Jf9PAAAA%2f%2f8%3d http://www.pexforfun.com/default.aspx?language=CSharp&co... UPDATE: I was wrong - Rex was integrated into Pex in 2010 and this made Pex much smarter when it has to deal with regular expressions.
- SanjayUttam 13y agoAnd more useful still if this worked on more than just portable class libraries [like the "original" Pex]