首页 > 解决方案 > 为 Android 中的单个测试添加拆卸块

问题描述

在 iOS 中,存在一个可以添加到调用的单独测试中的撕裂块,addTearDownBlock并将其放在单个测试中,它只会针对该单个测试执行。

android有类似的版本吗?

标签: androidtestingioteardown

解决方案


android 中的单元测试是使用称为 JUnit 的 xUnit 变体完成的。如果您使用的是 JUnit 4.0,请使用以下注解:

@AfterClass //Will only execute once after all the tests in the class have exhausted

@After //Will run after every test

如果您使用的是 JUnit 5.0,请使用以下注释:

@AfterEach //Will run after every test

@AfterAll //Will only execute once after all the tests in the class have exhausted

推荐阅读