You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Causeway从RC2升级RC4后单元测试断言失败求助

Apache Causeway 2.0.0-RC4升级后单元测试断言失败问题

我负责的项目基于Apache Causeway构建,目前正从2.0.0-RC2版本升级至2.0.0-RC4。升级后某单元测试执行失败,问题出在测试代码的这一行:

fixtureScripts.run(new RuleDefinition_persona.PersistAll());

其中RuleDefinition_persona是实现Persona<RuleDefinition, RuleDefinition_persona.Builder>的枚举,包含3个RuleDefinition持久化实体示例。该调用在RC2版本中正常运行,但在RC4中出现以下错误:

java.lang.AssertionError: bookmark required for non-empty scalars ObjectSpecificationDefault@2f2e4c19[class=rpe.modules.rules.dom.rule.RuleDefinition,type=ENTITY,superclass=rpe.modules.rules.dom.audited.AuditedEntity] ==> expected: but was:

我查阅了RC3和RC4的文档、发行说明及迁移指南,未找到任何关于bookmarks或“non-empty scalars”的相关内容。此外,我查看了断言所在的Causeway源码(org.apache.causeway.core.runtimeservices.executor.MemberExecutorServiceDefault:188),发现该代码在RC2到RC4之间未发生变更。

测试类继承自CausewayIntegrationTestAbstractWithFixtures,测试方法如下:

@Test
public void happyCase() {

    // given
    fixtureScripts.run(new RuleDefinition_persona.PersistAll());
    interactionService.nextInteraction();

    // when
    final List<RuleDefinition> all = wrap(menu).listAll();

    // then
    assertThat(all).hasSize(RuleDefinition_persona.values().length);
}

预期测试通过(即all列表包含3条数据),但实际结果失败:

Expected size: 3 but was: 0 in:
[]

若将测试方法第一行改为:

fixtureScripts.runPersonas(RuleDefinition_persona.values());

则会显示更明确的错误根源:

java.lang.AssertionError: bookmark required for non-empty scalars ObjectSpecificationDefault@2f2e4c19[class=rpe.modules.rules.dom.rule.RuleDefinition,type=ENTITY,superclass=rpe.modules.rules.dom.audited.AuditedEntity] ==> expected: <true> but was: <false>

请问是什么变更导致了该断言失败?这需要修改测试代码,还是Causeway的bug导致的?

内容的提问来源于stack exchange,提问作者Trevin Beattie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 11:20:15