I have some tests written using UiAutomator and I build and run them just fine using
gradlew cC (or gradlew connectedCheck).
However, I want to make my test project available without providing the source code.
Running
gradlew test
or
gradlew check
doesn't seem to do anything significant (event after a cleanTest).
Can anyone help me? It has to be possible... I just want to run the tests without having to provide their source code...
Following I give you some information that you may find useful. Btw, NameOfThePackage is the path to the package like com.stuff.xpto
My project structure is
project
build.gradle
app
build.gradle
src
androidTest
java
NameOfThePackage
MainFile.java //contains the tests
main
res/
AndroidManifest.xml
My AndroidManifest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="NameOfThePackage.test" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application>
</manifest>
My project/build.gradle is
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
My project/app/build.graddle is
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "NameOfThePackage"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
debuggable true
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
sourceSets{
androidTest.setRoot('src/androidTest')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.0.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support:support-annotations:23.1.0'
}
And Finally my MainFile.java is:
@RunWith(AndroidJUnit4.class)
public class MainFile{
@Before
public void setUp(){
//get instrumentation and stuff like that
}
@Test
public mainTest(){
//the test content
}
@After
tearDown(){
//clear stuff
}
Aucun commentaire:
Enregistrer un commentaire