Pex does not support decimal
So not able to do much this weekend I decided to use Pex to do some testing on a project I am busy on. The class I needed to test was a quote detail line where there is two quantities, of which only one can be specified depending on the property DealerSupplied. Here is the bare properties:
1: public decimal DealerQty
2: {
3: get
4: {
5: return _DealerQty;
6: }
7: set
8: {
9: if (!DealerSupplied && value != 0)
10: {
11: throw new ArgumentException("You cannot set the DealerQty if the product is not DealerSupplied.");
12: }
13:
14: SetPropertyValue("DealerQty", ref _DealerQty, value);
15: }
16: }
17:
18: public bool DealerSupplied
19: {
20: get
21: {
22: return _DealerSupplied;
23: }
24: set
25: {
26: SetPropertyValue("DealerSupplied", ref _DealerSupplied, value);
27: if (_DealerSupplied)
28: {
29: WMSQty = 0;
30: }
31: else
32: {
33: DealerQty = 0;
34: }
35: }
36: }
37:
38: public decimal WMSQty
39: {
40: get
41: {
42: return _WMSQty;
43: }
44: set
45: {
46: if (DealerSupplied && value != 0)
47: {
48: throw new ArgumentException("You cannot set the WMSQty if the product is DealerSupplied.");
49: }
50: SetPropertyValue("WMSQty", ref _WMSQty, value);
51: }
52: }
Initially I was guessing that I’d need at least 6 or 7 tests to test these three properties.
So how can Pex help me explore this code?
Well I thought I’d try the following code:
1: [PexMethod]
2: public void DealerSupplied_Qty_Test_Dec(bool dealerSupplied, decimal wmsQty, decimal dealerQty)
3: {
4: StubQuoteComponentBase target = new StubQuoteComponentBase();
5: target.DealerSupplied = dealerSupplied;
6: target.WMSQty = wmsQty;
7: target.DealerQty = dealerQty;
8: }
I was a bit surprised when I got only two tests back from Pex. I was even more surprised when I saw the values.
So my first reaction was to shoot of an email to Pex Support. I then tried to use int’s instead of decimal’s.
1: [PexMethod]
2: public void DealerSupplied_Qty_Test_Int(bool dealerSupplied, int wmsQty, int dealerQty)
3: {
4: StubQuoteComponentBase target = new StubQuoteComponentBase();
5: target.DealerSupplied = dealerSupplied;
6: target.WMSQty = wmsQty;
7: target.DealerQty = dealerQty;
8: }
This gave me a much better result:
Then I got an email from Nikolai, where he confirmed that Pex does not play well with the decimal value type. In his words: ‘all generated tests are bogus’ when using decimal as parameters.
Comments