Android Studio with JUnit validation

UPDATE

According to the new build system, the hierarchy should look like this:

MyProject/
  src/
      androidTest/
          java/
              com.example.app.test/
                  ... (source code for tests) ...
      main/
          AndroidManifest.xml
          java/
            com.example.app/
                ... (source code for main application) ...
          res/
              ... (resources for main application) ...

However, I do not have access to the private classes of the package in the com.example.app package. The build.gradle android object looks like this:

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        testPackageName "com.example.app.test"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        testFunctionalTest true
    }
}

I also tried using the old structure and getting the error message "The main manifest is not in the application /AndroidManifest.xml":

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    instrumentTest.setRoot('tests')
}

Do I need to use the old structure? What is missing in the new structure that would put the tests in the volume of the com.example.app package?

UPDATE 2:

I see an error in the AndroidManifest.xml tool file: "Cannot resolve the symbol" com.example.app "in the element

 <instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="com.example.app"/>

This is a test class:

package com.example.app.test;

import junit.framework.TestCase;

public class SimpleTest extends TestCase {

    public SimpleTest(String name) {
        super(name);
    }

    protected void setUp() throws Exception {
        super.setUp();
        assertTrue(true);
    }


    public void alwaysPasses() {

    }
}

I also tried extending AndroidTestCase and got this error with both parent classes:

!!! JUnit version 3.8 or later expected:

java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:185)
at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:168)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

, Android 1.6 | | . , , , junit Android .

+3
4

, (private-private):

MyProject/
  src/
      androidTest/
          java/
              com.example.app/
                  ... (source code for tests) ...
      main/
          AndroidManifest.xml
          java/
            com.example.app/
                ... (source code for main application) ...
          res/
              ... (resources for main application) ...
+1

, gradle. :

aidl.srcDirs = ['src']
0

Gradle .iml Android Studio. , 0.8.3 :

      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
  <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
  <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
  <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/androidTest/groovy" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
  <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
0

If you still adhere to this, I am creating an example project that independently uses the Espresso and Robotium tests!

https://github.com/hitherejoe/Android-Boilerplate

0
source

All Articles