0
then`块我是新来的斯波克和通过的文件已经走了,但还是不完全了解如何使用then
部分。如果我想比较两个字符串将在then
区块中进行什么操作?如何使用`在斯波克测试
setup:
def String1 = "books"
def String2 = new File('/path/to/file').text
when:
String1 = String1.toLowerCase()
String2 = String2.toLowerCase()
then:
if (String1 == String2) {
print "file contains the word" + String1
}
当两个字符串相等但当前通过测试时,我需要测试失败。
你不必测试表达式。你的话应该是'string1 == string2' –
不,它应该是'String1!= String2',因为当它们相等时测试会失败。但是请不要使用以大写字母开头的变量名称,因为按照惯例,您只能像这样写类名称。顺便说一句,测试也可以是:'expect:'(linefeed)'!new File('/ path/to/file')。text.toLowerCase()。contains(“books”)''。这对于某些人来说可能不那么容易阅读(虽然对我来说更容易些),但是也一样,甚至表示文本文件**包含该单词,而不是完全等于它。我认为测试不应该比必要更冗长。 – kriegaex