Runtime exception in Android JUnit testing

I have a simple HelloWorld activity that I am trying to test with the Android JUnit test. The application itself works as it should, but the test fails with

"java.lang.RuntimeException: Unable to enable action for: Intent {action = android.intent.action.MAIN flags = 0x10000000 comp = {no.helloworld.HelloWorld / no.helloworld.HelloWorld}} at no.helloworld.test.HelloWorldTestcase .setUp (HelloWorldTestcase.java:21) "

This is my activity class:

no.helloworld package

import android.app.Activity; import

android.os.Bundle;

public class HelloWorld extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
} }

And the test:

Public class HelloWorldTestcase extends ActivityInstrumentationTestCase2 {

private HelloWorld myActivity;
private TextView mView;
private String resourceString;
public HelloWorldTestcase() {
    super("no.helloworld.HelloWorld", HelloWorld.class);
}

@Override
protected void setUp() throws Exception {
    super.setUp();
    myActivity = this.getActivity();
    mView = (TextView) myActivity.findViewById(no.helloworld.R.id.txt1);
    resourceString = myActivity
            .getString(no.helloworld.R.string.helloworld);
}

public void testPreconditions() {
    assertNotNull(mView);
}

public void testText() {
    assertEquals(resourceString, (String) mView.getText());
}

protected void tearDown() throws Exception {
    super.tearDown();
}

? () AndroidManifest.xml, , .

+3
1

. "no.helloworld" "no.helloworld.HelloWorld"

+7

Source: https://habr.com/ru/post/1757125/


All Articles