Robolectric cannot find AndroidManifest.xml

This test passed normally initially. After a few days, you checked out a new branch (fixed by many other developers) and it no longer works.

Testing class in the mylibrary library module:

import com.company.mylibrary.BuildConfig;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, manifest = "src/main/AndroidManifest.xml", sdk = 21)
public class MyTest {

I also tried:

@Config(constants = BuildConfig.class, sdk = 21)
@Config(constants = BuildConfig.class, manifest = Config.NONE, sdk = 21)

In the build.gradle library module

dependencies {
    .
    .
    testCompile 'org.robolectric:robolectric:3.0'

Error message when starting inside AS: java.lang.RuntimeException: build/intermediates/manifests/full/debug/AndroidManifest.xml not found or not a file; it should point to your project AndroidManifest.xml

Error message when starting from the command line: com.company.mylibrary.framework1.feature1.MyTest > testMethod STANDARD_ERROR java.lang.RuntimeException: build/intermediates/manifests/full/debug/AndroidManifest.xml not found or not a file; it should point to your project AndroidManifest.xml

A) Don't know why it is looking there for the manifest B) That file/directory does not exist C) src/main/AndroidManifest.xml does exist

Things I tried: - deleted the build directory in that library module - restarted Android Studio - Build/Clean - Build/Rebuild Project - run the test (both inside AS and from command line) - and tried different versions of the @Config notation

It seems like I'm at rest, which I cannot understand.

I am working on a MacBook Pro. Android Studio 2.0 beta5

+4
source share
3 answers

You need to set the working directory in the test run configuration to the module directory. enter image description here

+7

, , , .

, , RobolectricTestRunner, RobolectricGradleTestRunner.

- AndroidManifest.xml, IMO , .

" ", : , . , Android Studio , , CLI (gradle :project:testBuildTypeUnitTest)

  • Java : System.getProperty('user.dir') . , , , , , .
  • RobolectricGradleTestRunner. , AndroidManifest.xml, res assets:

    public class CompassApplicationRobolectricTestRunner extends RobolectricGradleTestRunner {
    
    private static final int TARGET_SDK_VERSION = Build.VERSION_CODES.LOLLIPOP;
    private static final int MIN_SDK_VERSION = Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
    
    public CompassApplicationRobolectricTestRunner(Class<?> klass) throws InitializationError {
        super(klass);
    }
    
    @Override
    protected AndroidManifest getAppManifest(Config config) {
    
        final String manifestPath = PathResolver.resolveAndroidManifestPath();
        final String resourcesPath = PathResolver.resolveResPath();
        final String assetsPath = PathResolver.resolveAssetsPath();
    
        AndroidManifest manifest = new AndroidManifest(
                Fs.fileFromPath(manifestPath),
                Fs.fileFromPath(resourcesPath),
                Fs.fileFromPath(assetsPath)) {
            @Override
            public int getTargetSdkVersion() {
                return TARGET_SDK_VERSION;
            }
    
            @Override
            public int getMinSdkVersion() {
                return MIN_SDK_VERSION;
            }
        };
    
        return manifest;
    }
    }
    

, . , , , , , :

https://github.com/dawidgdanski/android-compass-api/blob/master/app-tests/src/test/java/pl/dawidgdanski/compass/PathResolver.java

, File.separator . , - , .

, , , , :

http://artemzin.com/blog/how-to-mock-dependencies-in-unit-integration-and-functional-tests-dagger-robolectric-instrumentation/

, .

0

( ) Android Studio, Roboelectric RELEASE. , - .

java.lang.RuntimeException: build/intermediates/manifests/release/AndroidManifest.xml not found or not a file; it should point to your project AndroidManifest.xml

I never did builds in this project, so the build directory was never created.

After the battle for bits without success (setting the path in the setup, trying to get the path in my CustomRoboelectric file), I just created a production assembly, so I had the release path created with the manifest, and it worked.

So, I decided to just run the assembly to create what Roboelectric wanted.

0
source

All Articles