大佬教程收集整理的这篇文章主要介绍了Android Studio - Junit 4 - 在所有测试之前运行代码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个应用程序,每当打开该应用程序时,我想强制执行 locale
。所以我将在应用程序的 Locale.setDefault(myCountryLocalE).
方法中使用 onCreate()
单元测试不会启动该类,因此我希望能够在启动测试时设置相同的语言环境。通过扩展程序或 gradle 脚本来设置语言环境,以便在运行它们的人使用其他语言环境时测试不会失败。
您可以使用 JUnit 的 TestSuite 来实现这一点。
package com.dinkar.test.sample;
import com.dinkar.test.sample.TestA;
import com.dinkar.test.sample.TESTB;
import com.dinkar.test.sample.TESTC;
import org.junit.AfterClass;
import org.junit.beforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import java.util.Locale;
/**
* @author dinkark on 29/04/20.
*
*/
@RunWith(Suite.class)
@SuiteClasses({TestA.class,TESTB.class,TESTC.class})
public class TestSuite {
@BeforeClass
public static void setUp() {
System.out.println("set config required by all the test cases");
System.out.println("This will only run once for all the test case included in TestA,TESTB,TESTC");
Locale.setDefault(myCountryLocalE);// set your locale
}
@AfterClass
public static void tearDown() {
System.out.println("clean up");
System.out.println("This will also run once only for all the test case included in TestA,TESTC");
}
}
@H_607_21@
以上是大佬教程为你收集整理的Android Studio - Junit 4 - 在所有测试之前运行代码全部内容,希望文章能够帮你解决Android Studio - Junit 4 - 在所有测试之前运行代码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。