顶点参数化单元测试中的值生成

时间:2011-07-21 11:23:45

标签: unit-testing moles pex

我正在使用Pex构建单元测试。我的问题不是所有的代码分支都在测试中,Pex继续生成参数值,这些参数值在相同条件下失败,使得该条件之后的所有代码都不能运行。

我的方法是这样的:

    public void SetUp(DbSyncScopeDescription SyncScopeDesc, BasicInfo info, string dbContext = "MyDBContext")
    {
        // <pex>
       Contracts validation
        // </pex>

        string localDbConnStr = string.Empty;

        //this condition never get a parameter that results in true
        if (IsContextExist(dbContext))
        {
            localDbConnStr = ConfigurationManager.ConnectionStrings[dbContext + "Context"].ConnectionString;
        }
        else
        {
            throw new MissingFieldException("dbcontext does not exist");
        }

        // This part is never being reached
        ProvisionLocalScope(SyncScopeDesc, info.FarmId, localDbConnStr);

        info.Tables = GetSyncTablesAsSyncTableInfo(SyncScopeDesc);
        AdminOrm.Create(info.ToORM(), String.Format("name={0}AdminEntities", dbContext));
    }

我想知道是否有可能告诉Pex通过该测试,以便所有代码都能到达。 如果这是不可能的话,可以让Pex在其中一个测试中采用函数参数的默认值(我认为如果不存在,这将是一个很好的特性)。

谢谢

0 个答案:

没有答案
相关问题