程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android Studio - Junit 4 - 在所有测试之前运行代码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Android studio - Junit 4 - 在所有测试之前运行代码?

开发过程中遇到Android studio - Junit 4 - 在所有测试之前运行代码的问题如何解决?下面主要结合日常开发的经验,给出你关于Android studio - Junit 4 - 在所有测试之前运行代码的解决方法建议,希望对你解决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@
@H_607_21@

大佬总结

以上是大佬教程为你收集整理的Android Studio - Junit 4 - 在所有测试之前运行代码全部内容,希望文章能够帮你解决Android Studio - Junit 4 - 在所有测试之前运行代码所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。