How to make test fail faster?

23 views
Skip to first unread message

Call Center 1001

unread,
Jul 4, 2017, 10:55:57 AM7/4/17
to Robolectric
java.lang.AssertionError
 at org
.junit.Assert.fail(Assert.java:86)
 at org
.junit.Assert.assertTrue(Assert.java:41)
 at org
.junit.Assert.assertTrue(Assert.java:52)
 at com
.example.app.FoodActivityTest.testSomething(FoodActivityTest.java:38)
 at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java
.lang.reflect.Method.invoke(Method.java:498)
 at org
.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 at org
.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at org
.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 at org
.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 at org
.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:488)
 at org
.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:209)
 at org
.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109)
 at org
.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36)
 at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
 at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
 at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
 at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
 at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
 at org
.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:63)
 at org
.junit.runners.ParentRunner.run(ParentRunner.java:363)
 at org
.junit.runner.JUnitCore.run(JUnitCore.java:137)
 at com
.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
 at com
.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
 at com
.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
 at com
.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
 at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java
.lang.reflect.Method.invoke(Method.java:498)
 at com
.intellij.rt.execution.application.AppMain.main(AppMain.java:147)


When fail

DescriptionDuration
Total Build Time16.900s
Startup1.382s
Settings and BuildSrc0.259s
Loading Projects0.287s
Configuring Projects2.417s
Task Execution10.442s

---- summary of failed submission tasks build time

:testReleaseUnitTest10.139s
:generateReleaseBuildConfig0.083sUP-TO-DATE
:prepareComAndroidSupportSupportV42410Library0.081sUP-TO-DATE
:compileReleaseRenderscript0.045sUP-TO-DATE
:compileReleaseJavaWithJavac0.013sUP-TO-DATE
:mergeReleaseResources0.012sUP-TO-DATE
:compileReleaseUnitTestJavaWithJavac0.011sUP-TO-DATE
:compileReleaseAidl0.010sUP-TO-DATE
:processReleaseResources0.008sUP-TO-DATE
:compileReleaseShaders0.007sUP-TO-DATE

When success

DescriptionDuration
Total Build Time7.110s
Startup1.482s
Settings and BuildSrc0.244s
Loading Projects0.259s
Configuring Projects2.531s
Task Execution0.316s


the snippet above are the output log from test-run




the test-case:

import android.widget.EditText;


import com.example.BuildConfig;
import com.example.R;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;


import static org.junit.Assert.assertTrue;




// start test junit
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class FoodActivityTest {
   
@Test
   
public void testSomething() throws Exception {
        assertTrue
(Robolectric.setupActivity(FoodActivity.class) != null);
       
FoodActivity foodActivity = Robolectric.setupActivity(FoodActivity.class);
       
EditText foodNameEditText = (EditText) foodActivity.findViewById(R.id.foodEditText);
        assertTrue
(foodNameEditText.getText().toString().contentEquals("Tomato"));


   
}
}


the activity:

// code
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

import com.example.R;

public class FoodActivity extends Activity {
    private EditText foodNameEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food);                         
        // foodNameEditText = (EditText) findViewById(R.id.foodEditText);
        // foodNameEditText.setText("Tomato");                                                  
    }
}


Reply all
Reply to author
Forward
0 new messages