黄瓜执行的集成测试往往会留下导致后续测试出现问题的上下文。显而易见的解决方案似乎是Spring的解决方案@DirtiesContext,但是它并没有在运行完所有黄瓜功能之后就删除上下文,而是在每种情况下都执行了此操作,因此使测试执行时间相当长。也尝试过@TestExecutionListeners,但没有运气。
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( classes = { MyApplication.class, MyTestComponent.class }, loader = SpringApplicationContextLoader.class )
@ActiveProfiles( { "test", "someotherprofile" } )
@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_CLASS )
@WebIntegrationTest( randomPort = true )
public class StepDefs extends StepDefUtils {
// givens, whens, thens
Run Code Online (Sandbox Code Playgroud)
我是否试图以不受支持的方式使用DirtiesContext?