【发布时间】:2022-11-12 04:48:45
【问题描述】:
因此,使用 Junit4,我可以通过 @RunWith 注释使用我自己的跑步者运行测试。 这非常强大,让我可以为每个测试使用我自己的“特殊”类加载器。 这个“特殊”类加载器的工作是在访问这些类时重新加载一个子集(实际上它可以实现不同的重新加载策略,但这不是重点)。 这有效地让我实现的是在“沙箱”中运行每个测试。
我有多个测试正在设置/要求不同的静态类变量值并行运行,而不会互相踩到脚趾。
我的问题是是否有可能使用新的 Junit5 达到相同的涅槃状态:)?
非常感谢您花时间查看和回答这个问题。
我的蛮力尝试使用 @ExtendWith 以及正在重新加载类并返回“重新加载”类的实例的 TestInstanceFactory 的自定义实现失败,但出现以下异常:
org.junit.jupiter.api.extension.TestInstantiationException message: TestInstanceFactory [<my implementation of TestInstanceFactory class name>] failed to return an instance of [<my-test-class>@<hash as loaded by original loader>] and instead returned an instance of [<my-test-class>@<hash as loaded by my special loader>].
【问题讨论】:
标签: junit junit5 junit5-extension-model