如何断言显示为字符串的货币值已正确更新
How to assert that currency value displayed as string has been correctly updated
我的自动化测试在更改值之前和之后返回了字符串值(之前 =“650 英镑中的 0 英镑”,之后 =“650 英镑中的 0.95 英镑”)。我进行的测试向帐户付款,然后返回检查值是否已正确修改。
如何检查字符串的值是否增加了 0.95?
我会使用正则表达式模式来匹配您的字符串的值,例如
var match = Regex.Match(input, @"£([0-9\.]+) of £([0-9\.]+)"); // pseudo code
然后对之前和之后执行此操作,提取匹配项,解析为十进制,然后进行比较...
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);
我的自动化测试在更改值之前和之后返回了字符串值(之前 =“650 英镑中的 0 英镑”,之后 =“650 英镑中的 0.95 英镑”)。我进行的测试向帐户付款,然后返回检查值是否已正确修改。
如何检查字符串的值是否增加了 0.95?
我会使用正则表达式模式来匹配您的字符串的值,例如
var match = Regex.Match(input, @"£([0-9\.]+) of £([0-9\.]+)"); // pseudo code
然后对之前和之后执行此操作,提取匹配项,解析为十进制,然后进行比较...
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);