Click here to Skip to main content
15,893,814 members
Articles / Programming Languages / C#

White box testing with PEX

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
3 Jan 2013CPOL14 min read 23.9K   139   7  
Problems related to maintenance of Unit test suites, using PEX tp help with the solution, and various PEX concepts like PEX Factories, PEX Method (PUT), Parameterize Mock and Partial Stubs.
// <copyright file="InsurerPexTest.cs" company="Microsoft">Copyright � Microsoft 2012</copyright>
using System;
using Microsoft.Pex.Framework;
using Microsoft.Pex.Framework.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SampleApp;
using SampleApp.DAL;
using SampleApp.Entity;

namespace SampleApp
{
    /// <summary>This class contains parameterized unit tests for Insurer</summary>
    [PexClass(typeof(Insurer))]
    [PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
    [PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
    [TestClass]
    public partial class InsurerPexTest
    {
        /// <summary>Test stub for .ctor(IDAL)</summary>
        [PexMethod]
        public Insurer Constructor(IDAL dal)
        {
            Insurer target = new Insurer(dal);
            return target;
            // TODO: add assertions to method InsurerPexTest.Constructor(IDAL)
        }

        /// <summary>Test stub for GetInsureAmount(Person)</summary>
        [PexMethod(MaxBranches=20000), PexAllowedException(typeof(NotEligibleException))]
        public float GetInsureAmount([PexAssumeUnderTest]Insurer target, Person p)
        {
            float result = target.GetInsureAmount(p);
            return result;
            // TODO: add assertions to method InsurerPexTest.GetInsureAmount(Insurer, Person)
        }

        [PexMethod, PexAllowedException(typeof(NotEligibleException))]
        public float GetInsureAmount01()
        {
            Insurer target = InsurerFactory.Create01();
            Person p = new Person();
            float result = target.GetInsureAmount(p);
            return result;
            // TODO: add assertions to method InsurerPexTest.GetInsureAmount(Insurer, Person)
        }

        /// <summary>Test stub for IsPersonEligible(Person)</summary>
        [PexMethod]
        public bool IsPersonEligible([PexAssumeUnderTest]Insurer target, Person p)
        {
            bool result = target.IsPersonEligible(p);            
            return result;
            // TODO: add assertions to method InsurerPexTest.IsPersonEligible(Insurer, Person)
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect TATA Communications
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions