我们遇到一个问题,迁移后某些 Pact 测试失败。看来测试忽略了合同日期的匹配规则。
匹配规则:
"$.entity.month": {
"matchers": [
{
"match": "date",
"format": "yyyy-MM"
}
],
Pact 的 Maven 依赖:
<dependency>
<groupId>au.com.dius.pact</groupId>
<artifactId>consumer</artifactId>
<version>4.1.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>java8</artifactId>
<version>4.1.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>junit5</artifactId>
<version>4.1.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5</artifactId>
<version>4.1.24</version>
<scope>test</scope>
</dependency>
测试的事件有一个格式为“yyyy-mm”的字段。但是,我得到以下输出:
1.1) body: $.entity.month Expected "2023-02" to match a date of 'yyyy-MM-dd': Unable to parse the date: 2023-02
似乎匹配器的“格式”字段被忽略,测试需要标准格式的日期。
我尝试过更改协议提供者和消费者的版本。但这根本没有帮助。会不会是Java版本的问题?
预期行为:测试为绿色。
我将版本更改为4.1.41后问题解决了。