2016-01-18 76 views
1

如何使用Assert函数检查比使用Assert函数进行CodedUI测试时大于小于Less的操作?大于检入编码的UI测试

我正在使用Visual Studio 2010 Ultimate。

+0

是我的答案有帮助?你需要更多信息? – DeJaVo

回答

1

您可以通过自定义代码来添加任何其他自定义断言。遵循以下步骤

首先在您的属性中添加任何声明并为验证方法生成代码。

移动验证方法UIMap.cs从UIMap.Designer.cs

现在自定义代码的验证方法UIMap.cs。这里有一个例子:

/// <summary> 
/// Verifies that the result count is > the min value passed. 
/// </summary> 
public void VerifyMinimumResultCount(int minResultCount) 
{ 
    HtmlSpan totalResults = 
     this.ApplicationWindow. 
     IntermediateParent.TotalResultsTextBox; 

    // Use regular expression to get the text out of the 
    // Control Property. 
    int actualResultCount; 
    Match resultPattern = Regex.Match(totalResults.Text, 
     "[0-9]+-[0-9]+ of ([0-9,]*) results"); 
    Assert.IsTrue(resultPattern.Success, 
     "Regular expression match failed"); 
    Assert.IsTrue(int.TryParse(resultPattern.Groups[1].Value, 
        NumberStyles.Number, 
        CultureInfo.CurrentCulture, 
        out actualResultCount), 
        "Parsing failed"); 
    Assert.IsTrue(actualResultCount >= minResultCount, 
      "Got less than expected min result"); 
} 

或者你可以使用AssertTrue:

//... 
int expectedValueLimit = 2; 
int actualValue = int.Parse(myUiControl.text); 
Assert.IsTrue((actualValue > expectedValueLimit), "myUiControl value is less than " + expectedValueLimit); 
//... 

来源:https://social.msdn.microsoft.com/Forums/en-US/da835e54-598b-4f3d-a5bf-6c4d1ea32de6/codedui-greater-than-assertion?forum=vsautotest