Mock class in class under test

You could refactor MyClass so that it uses dependency injection. Instead of having it create an AnythingPerformerClass instance you could pass in an instance of the class to the constructor of MyClass like so : class MyClass { private final AnythingPerformerClass clazz; MyClass(AnythingPerformerClass clazz) { this.clazz = clazz; } public boolean performAnything() { return clazz.doSomething(); … Read more

How to run unit tests with Android Studio

just add folder named instrumentTest under /src it should have /java inside like this then extend the class ActivityTestCase (or any other android unit-test-class), such as package com.example.app.test; import android.test.ActivityTestCase; import junit.framework.Assert; public class MainActivityTest extends ActivityTestCase { public void testHappy(){ Assert.assertTrue(true); } } right click on green java directory and select run all tests … Read more

Robolectric – Package targetSdkVersion=30 > maxSdkVersion=29

Found this post with the same issue, with a different error message. This answer helped me to solve the issue. Posting the same here. Create a robolectric.properties file inside the app/src/test/resources directory with the following line: sdk=29 This will force Robolectric to use API 29 instead of 30. Note: Robolectric supports up to SDK 29 … Read more