Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Upgrade to spoon2.0.0-snapshot, android3.0.0 and gradle 4.1 #161

Closed
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ android:
components:
- tools
- platform-tools
- build-tools-23.0.3
- build-tools-26.0.2
- android-24
- sys-img-armeabi-v7a-android-21
- extra-android-m2repository
- sys-img-armeabi-v7a-android-24
licenses:
- 'android-sdk-license-.+'

Expand All @@ -32,9 +32,10 @@ install:
- ./gradlew -q assemble

before_script:
- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
- android list targets
- echo no | android create avd --force -n test -t android-24 --abi armeabi-v7a
- mksdcard -l e 512M sdcard.img
- emulator -avd test -no-skin -no-audio -no-window -sdcard sdcard.img &
- emulator -avd test -no-window -sdcard sdcard.img &
- android-wait-for-emulator
- adb shell input keyevent 82

Expand Down
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ apply plugin: 'nexus'
apply plugin: 'project-report'

group = 'com.stanfy.spoon'
version = '1.2.3-SNAPSHOT'
version = '2.0.0-SNAPSHOT'

jar {
manifest {
Expand All @@ -31,15 +31,20 @@ targetCompatibility = 1.6
repositories {
mavenCentral()
mavenLocal()
google()
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // for spoon snapshot
}

dependencies {
compile gradleApi()
compile localGroovy()

compile 'com.squareup.spoon:spoon-runner:1.7.1'
compile 'com.squareup.spoon:spoon-runner:2.0.0-SNAPSHOT'

compile 'com.android.tools.build:gradle:1.5.0'
compile('com.android.tools.build:gradle:3.0.0') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update it to 3.0.1 ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I am trying :)

exclude group: 'org.jetbrains.trove4j'
}

testCompile('org.spockframework:spock-core:0.7-groovy-2.0') {
exclude group: 'org.codehaus.groovy'
Expand Down
17 changes: 11 additions & 6 deletions example/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ apply plugin: 'spoon'

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
buildToolsVersion '26.0.2'

defaultConfig {
minSdkVersion 8
minSdkVersion 9
targetSdkVersion 24

versionCode 1
Expand All @@ -23,13 +23,13 @@ android {
testCoverageEnabled = true
}
}

flavorDimensions "main"
productFlavors {
free {

dimension "main"
}
pro {

dimension "main"
}
}

Expand Down Expand Up @@ -69,10 +69,15 @@ spoon {

repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // for spoon snapshot
google()
}

dependencies {
androidTestCompile "com.squareup.spoon:spoon-client:1.6.4"
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.squareup.spoon:spoon-client:2.0.0-SNAPSHOT'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test:rules:0.5'
}

// for integration test of this plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
package com.stanfy.spoon.example.test;

import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.UiThreadTest;
import android.support.test.annotation.UiThreadTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.widget.TextView;

import com.squareup.spoon.Spoon;
import com.squareup.spoon.SpoonRule;
import com.stanfy.spoon.example.MainActivity;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

/**
* Tests for MainActivity.
*/
public class AnotherMainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
@RunWith(AndroidJUnit4.class)
public class AnotherMainActivityTest {

@Rule
public final SpoonRule spoon = new SpoonRule();
@Rule
public final ActivityTestRule<MainActivity> activityRule =
new ActivityTestRule<>(MainActivity.class);

public AnotherMainActivityTest() {
super(MainActivity.class);
}

@Test
@UiThreadTest
public void testSetText() throws Throwable {
final MainActivity act = getActivity();
MainActivity act = activityRule.getActivity();
final TextView text = (TextView) act.findViewById(android.R.id.text1);
assertNotNull(text);
Spoon.screenshot(act, "startup");
spoon.screenshot(act, "startup");

final int steps = 5;
for (int i = 1; i <= steps; i++) {
final String step = String.valueOf(i);
act.setText(step);
Spoon.screenshot(act, "step-" + i);
spoon.screenshot(act, "step-" + i);
assertEquals(text.getText().toString(), step);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.stanfy.spoon.example.test;

import android.os.Bundle;
import android.test.InstrumentationTestRunner;
import android.support.test.runner.AndroidJUnitRunner;
import android.util.Log;

/** Custom runner implementation to check how arguments are passed. */
public class CustomTestRunner extends InstrumentationTestRunner {
public class CustomTestRunner extends AndroidJUnitRunner {

public void onCreate(final Bundle arguments) {
if (arguments == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,70 @@
package com.stanfy.spoon.example.test;

import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.support.test.annotation.UiThreadTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.UiThreadTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.widget.TextView;

import com.squareup.spoon.Spoon;
import com.squareup.spoon.SpoonRule;
import com.stanfy.spoon.example.MainActivity;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

/**
* Tests for MainActivity.
*/
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {

@RunWith(AndroidJUnit4.class)
public class MainActivityTest {

public MainActivityTest() {
super(MainActivity.class);
}
@Rule
public final SpoonRule spoon = new SpoonRule();
@Rule
public final ActivityTestRule<MainActivity> activityRule =
new ActivityTestRule<>(MainActivity.class);

@Test
@UiThreadTest
public void testSetText() throws Throwable {
final MainActivity act = getActivity();
final MainActivity act = activityRule.getActivity();
final TextView text = (TextView) act.findViewById(android.R.id.text1);
assertNotNull(text);
Spoon.screenshot(act, "startup");
spoon.screenshot(act, "startup");

final int steps = 5;
for (int i = 1; i <= steps; i++) {
final String step = String.valueOf(i);
act.setText(step);
Spoon.screenshot(act, "step-" + i);
spoon.screenshot(act, "step-" + i);
assertEquals(text.getText().toString(), step);
}

}

@SmallTest
public void testSmallTest() throws Throwable {
final MainActivity act = getActivity();
Spoon.screenshot(act, "startup-smallTest");
final MainActivity act = activityRule.getActivity();
spoon.screenshot(act, "startup-smallTest");
}

@MediumTest
public void testMediumTest() throws Throwable {
final MainActivity act = getActivity();
Spoon.screenshot(act, "startup-mediumTest");
final MainActivity act = activityRule.getActivity();
spoon.screenshot(act, "startup-mediumTest");
}

@LargeTest
public void testLargeTest() throws Throwable {
final MainActivity act = getActivity();
Spoon.screenshot(act, "startup-largeTest");
final MainActivity act = activityRule.getActivity();
spoon.screenshot(act, "startup-largeTest");
}

}
7 changes: 5 additions & 2 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ buildscript {
repositories {
mavenCentral()
mavenLocal()
jcenter()
google()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // for spoon snapshot
}

dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.3-SNAPSHOT'
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.stanfy.spoon:spoon-gradle-plugin:2.0.0-SNAPSHOT'
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
26 changes: 16 additions & 10 deletions src/main/groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,19 @@ class SpoonPlugin implements Plugin<Project> {
throw new UnsupportedOperationException("Spoon plugin for gradle currently does not support abi/density splits for test apks")
}
SpoonExtension config = project.spoon
return testVariant.testedVariant.outputs.collect { def projectOutput ->
return testVariant.outputs.collect { def projectOutput ->
SpoonRunTask task = project.tasks.create("${TASK_PREFIX}${testVariant.name.capitalize()}${suffix}", SpoonRunTask)
task.configure {
group = JavaBasePlugin.VERIFICATION_GROUP

def instrumentationPackage = testVariant.outputs[0].outputFile
if (projectOutput instanceof ApkVariantOutput) {
applicationApk = projectOutput.outputFile
} else {
// This is a hack for library projects.
// We supply the same apk as an application and instrumentation to the soon runner.
applicationApk = instrumentationPackage
}
instrumentationApk = instrumentationPackage

File outputBase = config.baseOutputDir
if (!outputBase) {
outputBase = new File(project.buildDir, "spoon")
}
output = new File(outputBase, projectOutput.dirName)
output = new File(outputBase, testVariant.testedVariant.name)

debug = config.debug
ignoreFailures = config.ignoreFailures
Expand Down Expand Up @@ -151,8 +144,21 @@ class SpoonPlugin implements Plugin<Project> {
shardIndex = config.shardIndex
}

dependsOn projectOutput.assemble, testVariant.assemble
dependsOn testVariant.testedVariant.assemble, testVariant.assemble
}

task.doFirst {
def testedOutput = testVariant.testedVariant.outputs[0]

if (testedOutput instanceof ApkVariantOutput) {
task.applicationApk = testedOutput.outputFile
} else {
// This is a hack for library projects.
// We supply the same apk as an application and instrumentation to the soon runner.
task.applicationApk = task.instrumentationApk
}
}

task.outputs.upToDateWhen { false }
return task
} as List<SpoonRunTask>
Expand Down
Loading