Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit4 - AssertionFailedError: No tests found

I'm using AndroidJUnitRunner with Espresso.

I wrote a simple test but always receive this exception. According to Stackoverflow answers, the problem is messing up the JUnit3 and JUnit4 but I have never used JUnit3 in my project.

junit.framework.AssertionFailedError: No tests found in com.walletsaver.app.test.espresso.SignUpPopupTest

package com.walletsaver.app.test.espresso;  import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest;  import com.walletsaver.app.activity.LoginActivity;  import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith;  import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.matcher.ViewMatchers.withText;  @RunWith(AndroidJUnit4.class) @SmallTest public class SignUpPopupTest {      @Rule     public ActivityTestRule<LoginActivity> mActivityRule =             new ActivityTestRule<>(LoginActivity.class);      @Test     public void checkSignUpPopup() throws Exception {         onView(withText("Sign Up")).perform(click());     } } 

Run configuration: enter image description here

Output: enter image description here

like image 309
Val Avatar asked Dec 22 '15 17:12

Val


People also ask

How do you resolve Testng no tests found nothing was run?

Solution. The easiest solution would be to change the @BeforeTest annotation with @Test and execute you Test case / Test Suite. Save this answer.

Which of the following is correct about fixture?

Q 14 - Which of the following is correct about Fixture? A - Fixture is a fixed state of a set of objects used as a baseline for running tests.

Which of the following annotation causes that method to run once after all tests have finished?

@AfterSuite: A method with this annotation will run once after the execution of all tests in the suite is complete.


1 Answers

I found the problem. It was missed code in build.gradle in the main module. If you have this problem I advise to start with adding this line:

android {     ...      defaultConfig {         ...          testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'     } ... } 
like image 145
Val Avatar answered Sep 19 '22 17:09

Val