├── .gitignore ├── IntelliJJUnitPatcher.jar ├── IntelliJJUnitPatcher.iml ├── META-INF └── plugin.xml ├── README.md └── src └── de └── mobilej └── intellij └── StudioJUnitPatcher.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .idea 3 | -------------------------------------------------------------------------------- /IntelliJJUnitPatcher.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjoernQ/IntelliJJUnitPatcher/master/IntelliJJUnitPatcher.jar -------------------------------------------------------------------------------- /IntelliJJUnitPatcher.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | de.mobilej.junitpatcher 3 | JUnitPatcher 4 | 1.0 5 | www.mobile-j.de 6 | 7 | 10 | 11 | 13 | ]]> 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED AS OF Android Studio 1.1-beta3 / Android Gradle Plugin 1.1.0-rc1 - WON'T WORK ANYMORE AND YOU SHOULD USE THE NOW BUILT IN FUNCTIONALITY 2 | 3 | # JUnitPatcher for Android Studio 4 | 5 | This is a very simple plugin which should enable the execution of JUnit tests in the JVM from inside Android Studio. 6 | 7 | It plays together with the Robolectric Gradle Plugin. 8 | 9 | After installation into Android Studio (tested with 0.8.7) it will patch the classpath of generated JUnit run configurations. 10 | 11 | There is just one thing you should change in your build.gradle file.Add 12 | 13 | ``` 14 | // always compile tests when assembling the app 15 | afterEvaluate { project -> 16 | String variantTestCompileTaskName = 'compileTestDebugJava'; 17 | boolean found = false; 18 | 19 | project.tasks.each() { task -> 20 | String taskName = task.name; 21 | if(taskName.startsWith("compileTest") && taskName.endsWith("Java")){ 22 | if(!found){ 23 | variantTestCompileTaskName = taskName; 24 | } 25 | found = true; 26 | } 27 | }; 28 | 29 | project.tasks.each() { task -> 30 | String taskName = task.name; 31 | if(taskName.startsWith("assemble")){ 32 | String variantName = taskName.substring(8); 33 | task.dependsOn(variantTestCompileTaskName); 34 | } 35 | }; 36 | 37 | } 38 | ``` 39 | 40 | 41 | to your build file. This way Studio will compile the tests whenever the debug configuration is compiled. 42 | Otherwise it's possible you will run old versions of your tests in Studio and changes to the tests are not taken into account when running the tests. 43 | 44 | -------------------------------------------------------------------------------- /src/de/mobilej/intellij/StudioJUnitPatcher.java: -------------------------------------------------------------------------------- 1 | package de.mobilej.intellij; 2 | 3 | import com.intellij.execution.JUnitPatcher; 4 | import com.intellij.execution.configurations.JavaParameters; 5 | import com.intellij.openapi.module.Module; 6 | import com.intellij.util.PathsList; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.io.File; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * Simple JUnitPatcher. 15 | * 16 | * Moves first four elements of the classpath to the end and adds "./build/test-classes/" to the classpath. 17 | * 18 | * Created by bjoern on 29.08.14. 19 | */ 20 | public class StudioJUnitPatcher extends JUnitPatcher { 21 | 22 | @Override 23 | public void patchJavaParameters(@Nullable Module module, JavaParameters javaParameters) { 24 | 25 | // MODIFY THE CLASSPATH HERE! 26 | PathsList classpath = javaParameters.getClassPath(); 27 | List pathList = classpath.getPathList(); 28 | 29 | ArrayList moveToEnd = new ArrayList(); 30 | moveToEnd.add( pathList.get(0) ); 31 | moveToEnd.add( pathList.get(1) ); 32 | moveToEnd.add( pathList.get(2) ); 33 | moveToEnd.add( pathList.get(3) ); 34 | 35 | for(String s : moveToEnd){ 36 | classpath.remove(s); 37 | } 38 | 39 | for(String s : moveToEnd){ 40 | classpath.add(s); 41 | } 42 | 43 | 44 | // add test classes 45 | 46 | // they are only built when "compileTestDebugJava" is executed 47 | // so add 48 | // "assembleDebug.dependsOn('compileTestDebugJava')" to your gradle.build to always have 49 | // the classes in sync with the test sources. 50 | classpath.add( new File( new File(module.getModuleFilePath()).getParent() ,"build/test-classes/") ); 51 | 52 | } 53 | 54 | } 55 | --------------------------------------------------------------------------------