【问题标题】:Sandboxed tests with Junit5 (Is Junit4 @RunWith more powerful compared to Junit5 @ExtendWith)使用 Junit5 进行沙盒测试(与 Junit5 @ExtendWith 相比,Junit4 @RunWith 是否更强大)
【发布时间】: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


    【解决方案1】:

    显然在 Junit5 中是可能的。 请参阅 github 讨论和建议的解决方案: https://github.com/junit-team/junit5/issues/3028#issuecomment-1286880925

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2019-12-19
      • 1970-01-01
      相关资源
      最近更新 更多