Code coverage is working!

Been trying so long to get this running, so happy to have it done.
This commit is contained in:
Bradlee Speice 2014-11-17 13:35:15 -05:00
parent 8d6a3b0d84
commit cb8ea71f62
8 changed files with 64 additions and 57 deletions

View File

@ -1,14 +1,3 @@
language: android language: java
env:
matrix:
- ANDROID_SDKS=android-19,sysimg-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
before_install: script: "bash gradlew jacocoTestReport"
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
before_script:
- bash ./wait_for_emulator
- adb shell input keyevent 82 &
script: "bash gradlew connectedAndroidTestTestConfigDebug"

1
app-test/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

32
app-test/build.gradle Normal file
View File

@ -0,0 +1,32 @@
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'jacoco'
def androidModule = project(':app')
dependencies {
compile androidModule
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.classpath
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.outputs.files
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
testCompile 'junit:junit:4.+'
testCompile 'org.robolectric:robolectric:2.2'
}
jacocoTestReport {
// Add Android sources/classes for coverage
additionalSourceDirs files(androidModule.android.sourceSets.main.java.srcDirs)
additionalClassDirs androidModule.android.applicationVariants
.toList().first().javaCompile.outputs.files
reports {
xml.enabled true
csv.enabled false
html.destination "${buildDir}/jacocoHtml"
}
}
// Code coverage should depend on the tests
project.jacocoTestReport.dependsOn project.test

View File

@ -0,0 +1,25 @@
package org.bspeice.minimalbible
import org.junit.Before
import org.junit.Test
import kotlin.properties.Delegates
class SafeValDelegateKotlinTest {
var delegate: SafeValDelegate<String> by Delegates.notNull()
Before fun setUp() {
delegate = SafeValDelegate()
}
Test(expected = javaClass<IllegalStateException>())
fun testDelegateNullSafety() {
delegate.get(null, PropertyMetadataImpl(""))
}
Test(expected = javaClass<IllegalStateException>())
fun testDelegateAssignOnce() {
delegate.set(null, PropertyMetadataImpl(""), "")
delegate.set(null, PropertyMetadataImpl(""), "")
}
}

View File

@ -1,12 +1,9 @@
buildscript { buildscript {
ext.kotlin_version = '0.9.206'
repositories { repositories {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }

View File

@ -1,39 +0,0 @@
package org.bspeice.minimalbible.test;
import org.bspeice.minimalbible.MBTestCase;
import org.bspeice.minimalbible.SafeValDelegate;
import kotlin.PropertyMetadataImpl;
/**
* Test that the FinalDelegate actually obeys its contract
*/
public class SafeValDelegateTest extends MBTestCase {
SafeValDelegate<String> delegate;
public void setUp() {
delegate = new SafeValDelegate<String>();
}
public void testDelegateNullSafety() {
try {
delegate.get(null, new PropertyMetadataImpl(""));
} catch (IllegalStateException e) {
return;
}
fail("Exception not thrown!");
}
public void testDelegateAssignOnce() {
try {
delegate.set(null, new PropertyMetadataImpl(""), "");
delegate.set(null, new PropertyMetadataImpl(""), "");
} catch (IllegalStateException e) {
return;
}
fail("Allowed to set twice!");
}
}

View File

@ -1,12 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '0.9.206'
repositories { repositories {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:0.12.+' classpath 'com.android.tools.build:gradle:0.12.+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }

View File

@ -1,2 +1,2 @@
include ':app' include ':app', ':app-test'
include ':jsword-minimalbible' include ':jsword-minimalbible'