gpt4 book ai didi

android - 我收到错误 "No instrumentation registered! Must run under a registering instrumentation"

转载 作者:行者123 更新时间:2023-11-30 05:10:42 26 4
gpt4 key购买 nike

当我尝试运行 SignUpFragmentTest 类时,出现错误“未注册检测!必须在注册检测下运行”。我认为当我使用@Rule 时会抛出错误。

import android.support.test.runner.AndroidJUnit4;
import android.support.v4.app.Fragment;
import android.widget.FrameLayout;



import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.rule.ActivityTestRule;
import static junit.framework.Assert.assertNotNull;



@RunWith(AndroidJUnit4.class)

public class SignUpFragmentTest {

@Rule public final ActivityTestRule<LoginActivity> main = new ActivityTestRule<>(LoginActivity.class);

private LoginActivity mActivity = null;



@Before
public void setUp() throws Exception {
mActivity =main.getActivity();
}
@Test
public void testLaunchSingUpScreen(){
FrameLayout frameLayout = mActivity.findViewById(R.id.fragment_container);
assertNotNull(frameLayout);
Fragment fragment = new SignUpFragment();
mActivity.getSupportFragmentManager().beginTransaction().add(frameLayout.getId(),fragment).commitAllowingStateLoss();

}
@After
public void tearDown() throws Exception {
mActivity= null;
}
}

我添加到依赖项:

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

默认配置

最佳答案

对我有用的是将所有库从

androidX

com.android.support

build.gradle 中的库

请注意:您可能需要重新导入库以测试您的类,例如

import androidx.test.runner.AndroidJUnitRunner;

import android.support.test.runner.AndroidJUnitRunner;

还要确保在每次从 build.gradle 添加或删除库后始终清理并重建项目。

关于android - 我收到错误 "No instrumentation registered! Must run under a registering instrumentation",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53805745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com