我的自动化测试中返回的值在值更改之前和之后(在=“£0£650”之前,之后=“£0.95£650”)。我进行的测试是对帐户进行付款,然后返回检查值是否已正确修改。
如何检查字符串的值是否已增加0.95?
答案 0 :(得分:1)
我会使用正则表达式模式来匹配字符串的值,例如
var match = Regex.Match(input, @"£([0-9\.]+) of £([0-9\.]+)"); // pseudo code
然后在之前和之后执行此操作,提取匹配项,解析为十进制,然后比较...
答案 1 :(得分:0)
int originalIndex = currentValue.IndexOf(" ");
int newIndex = newValue.IndexOf(" ");
currentValue = currentValue.Substring(0, originalIndex);
newValue = newValue.Substring(0, newIndex);
double origCash = double.Parse(currentValue, NumberStyles.Currency);
double newCash = double.Parse(newValue, NumberStyles.Currency);
Assert.IsTrue(newCash == origCash+valueAdded);