Sneha Maheshwari
Sneha Maheshwari

Reputation: 11

Using Roboletric for Junit testing

No such manifest file: build/intermediates/bundles/debug/app/src/main/AndroidManifest.xml

Refered to -Robolectric says "AndroidManifest.xml not found"

https://github.com/robolectric/robolectric/issues/1648 but was not helpful.

Upvotes: 1

Views: 119

Answers (2)

kwounsu
kwounsu

Reputation: 1

You can fix the No such manifest file: ./AndroidManifest.xml warning, by updating your gradle file.

Add the following line to your gradle file to so that the correct Android manifest is used. The includeAndroidResources option allows you to access android resources in your unit tests, including your AndroidManifest file. app/build.gradle

testOptions.unitTests {
    includeAndroidResources = true
}

src: https://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-testing-basics/index.html?index=..%2F..index#7

Upvotes: 0

Dany Pop
Dany Pop

Reputation: 3658

Check your gradle and your class :

Gradle :

 testCompile 'org.robolectric:robolectric:3.3'
 testCompile 'junit:junit:4.12'
 testCompile 'org.assertj:assertj-core:1.7.1'

In your test Class :

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 25)
public class YourTest {

    @Test
    public void shouldNotBeNull() throws Exception {
       //put your test here for example
    }
)

YourTest class should be put in Test folder (not AndroidTest folder)

On Android Studio :

  • Edit Configurations
  • In Junit, you have to change the working directory to $MODULE_DIR$. The important thing is $MODULE_DIR$.

Upvotes: 1

Related Questions