如何断言包含特殊字符的字符串


  • def 错误消息 ='客户端版本无效。客户端版本不能包含以下任何字符:\"&'(),/:;<>\'

  • def 预期消息 ='客户端版本无效。客户端版本不能包含以下任何字符:\"&'(),/:;<>\'

然后匹配错误消息包含预期的消息。

由于我的错误消息和预期消息中包含特殊字符,因此断言失败

你转义了几个特殊字符,如单引号和双引号,

# Client version is invalid. The client version cannot contain any of the following characters: "&'(),/:;<>
* def errorMessage = 'Client version is invalid. The client version cannot contain any of the following characters: \"&'(),/:;<>'
* def expectedMessage = 'Client version is invalid. The client version cannot contain any of the following characters: \"&'(),/:;<>'
* match errorMessage == expectedMessage

最新更新