在文件夹handleChange = () => {
console.log("hoer");
this.props.change(
"selectingFormValues",
"totaal",
total(this.props.amount1 + this.props.amount2)
);
};
我有3个要测试的json文件:
app\src\androidTest\assets\
这里是意式浓缩咖啡的测试:
trader_0_wallet.json
trader_1_wallet.json
trader_6_wallet.json
正如您在@RunWith(AndroidJUnit4::class)
class TraderDetailsActivityTest {
val targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext()
val context = InstrumentationRegistry.getInstrumentation().getContext()
@get:Rule
var traderDetailsActivityRule: ActivityTestRule<TraderDetailsActivity> = ActivityTestRule(TraderDetailsActivity::class.java, false, false)
@Before
fun setup() {
val intent = Intent(targetContext, TraderDetailsActivity::class.java)
val bundle = Bundle()
val inputStream = context.assets.open("trader_0_wallet.json")
val content = inputStream.readBytes().toString(StandardCharsets.UTF_8)
val trader: Trader = GsonUtil.gson.fromJson(content, Trader::class.java)
bundle.putSerializable(TraderDetailsActivity.TRADER, trader)
intent.putExtras(bundle)
traderDetailsActivityRule.launchActivity(intent)
}
@Test
fun list_0_wallet() {
// test activity without wallets
// need file trader_0_wallet.json
}
@Test
fun list_1_wallet() {
// test activity with one wallet
// need file trader_1_wallet.json
}
@Test
fun list_6_wallet() {
// test activity with six wallets
// need file trader_6_wallet.json
}
方法中所看到的,我仅读取一个文件setup
。结果,测试trader_0_wallet.json
通过,但测试list_0_wallet
和list_1_wallet
失败。
因为测试list_6_wallet
需要文件list_1_wallet
,而测试trader_1_wallet.json
需要文件list_6_wallet
如何为每次测试加载正确的文件?