Build coverage report (#3)

Add first unit test & code coverage config
This commit is contained in:
Mikołaj Pich 2017-07-20 17:37:55 +02:00 committed by GitHub
parent 9d98173b04
commit 4b425f9b39
10 changed files with 68 additions and 44 deletions

View File

@ -1,6 +1,7 @@
# Wulkanowy
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b0365aa6584a4c1abf36141204bc8de3)](https://www.codacy.com/app/mklkj/wulkanowy?utm_source=github.com&utm_medium=referral&utm_content=wulkanowy/wulkanowy&utm_campaign=badger)
[![Codacy Grade Badge](https://api.codacy.com/project/badge/Grade/b0365aa6584a4c1abf36141204bc8de3)](https://www.codacy.com/app/wulkanowy/wulkanowy)
[![Codacy Coverage Badge](https://api.codacy.com/project/badge/Coverage/b0365aa6584a4c1abf36141204bc8de3)](https://www.codacy.com/app/wulkanowy/wulkanowy)
[![Build Status](https://www.bitrise.io/app/daeff1893f3c8128.svg?token=Hjm1ACamk86JDeVVJHOeqQ&branch=master)](https://www.bitrise.io/app/daeff1893f3c8128)
[![CircleCI](https://circleci.com/gh/wulkanowy/wulkanowy.svg?style=svg)](https://circleci.com/gh/wulkanowy/wulkanowy)

View File

@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'jacoco-android'
apply plugin: "io.github.ddimtirov.codacy"
android {
compileSdkVersion 25
@ -17,6 +19,9 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = true
}
}
}

View File

@ -1,30 +1,19 @@
package io.github.wulkanowy.activity.main;
import org.jsoup.Connection;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Element;
import java.io.IOException;
class CheckPass {
public class CheckPass {
private Document document;
Connection.Response page;
public CheckPass (Connection.Response pageT){
page = pageT;
CheckPass(Document doc) {
document = doc;
}
public String start (){
try{
Document document = page.parse();
Elements mesageAlert = document.getElementsByClass("ErrorMessage center");
return mesageAlert.text();
}
catch (IOException e){
return e.toString();
}
boolean isLogged() {
Element messageAlert = document.select(".ErrorMessage").first();
return null == messageAlert;
}
}

View File

@ -72,6 +72,7 @@ public class Login extends AsyncTask<Void, Void, Void> {
try {
if (!stepOne()) {
userMesage = activity.getString(R.string.login_bad_credentials);
return null;
}
@ -106,10 +107,9 @@ public class Login extends AsyncTask<Void, Void, Void> {
loginCookies = initial.cookies();
CheckPass checkPass = new CheckPass(initial);
userMesage = checkPass.start();
Document document = initial.parse();
return userMesage.isEmpty();
return new CheckPass(document).isLogged();
}
private Document stepTwo() throws IOException {

View File

@ -11,6 +11,7 @@
<string name="data_text">Brak danych logowania</string>
<string name="error_feature_text">Funkcja którą chciałeś uruchomić nie działa</string>
<string name="login_accepted">Pomyślnie zalogowano</string>
<string name="login_bad_credentials">Zła nazwa użytkownika lub hasło</string>
<string name="login_denied">Logowanie nie powiodło się</string>
<string name="please_wait">Proszę czekać…</string>
<string name="title_activity_dashboard">Aktywność dashboard</string>

View File

@ -11,6 +11,7 @@
<string name="data_text">No login data</string>
<string name="error_feature_text">The function you wanted to run does not work</string>
<string name="login_accepted">Login is successful</string>
<string name="login_bad_credentials">Bad username or password</string>
<string name="login_denied">Login is failed</string>
<string name="please_wait">Please wait…</string>
<string name="title_activity_dashboard">Dashboard Activity</string>

View File

@ -1,17 +0,0 @@
package io.github.wulkanowy;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

View File

@ -0,0 +1,28 @@
package io.github.wulkanowy.activity.main;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Test;
import static org.junit.Assert.*;
public class CheckPassTest {
@Test
public void testFailureLogin() throws Exception {
String html = "<div class='ErrorMessage center'>Zła nazwa użytkownika lub hasło</div>";
Document doc = Jsoup.parse(html);
CheckPass obj = new CheckPass(doc);
assertFalse(obj.isLogged());
}
@Test
public void testSuccessfulLogin() throws Exception {
String html = "<title>Working...</title>";
Document doc = Jsoup.parse(html);
CheckPass check = new CheckPass(doc);
assertTrue(check.isLogged());
}
}

View File

@ -3,12 +3,17 @@
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
classpath "gradle.plugin.io.github.ddimtirov:codacy-gradle-plugin:0.1.0"
}
}

View File

@ -7,18 +7,29 @@ machine:
dependencies:
pre:
- wget "https://downloads.gradle.org/distributions/gradle-2.3-bin.zip"; unzip gradle-2.3-bin.zip
- wget "https://downloads.gradle.org/distributions/gradle-3.3-bin.zip"; unzip gradle-3.3-bin.zip
override:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-25.0.2,android-25,extra-google-m2repository,extra-google-google_play_services,extra-android-m2repository
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-25.0.3,android-25,extra-google-m2repository,extra-google-google_play_services,extra-android-m2repository
# Constraint Layout / [Solver for ConstraintLayout 1.0.0-alpha8, ConstraintLayout for Android 1.0.0-alpha8]
- mkdir -p $ANDROID_HOME/licenses/
- echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license
- echo "84831b9409646a918e30573bab4c9c91346d8abd" > $ANDROID_HOME/licenses/android-sdk-preview-licens
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
compile:
pre:
- ./gradlew --version
override:
- ./gradlew assembleDebug
post:
- mv app/build/outputs/apk/app-debug.apk $CIRCLE_ARTIFACTS
test:
override:
- ./gradlew test
- ./gradlew check
- ./gradlew assembleDebug
- cp app/build/outputs/apk/app-debug.apk $CIRCLE_ARTIFACTS
- ./gradlew codacyUpload
post:
- mv app/build/reports/tests/ $CIRCLE_ARTIFACTS/tests
- mv app/build/reports/lint-results.html $CIRCLE_ARTIFACTS
- mv app/build/reports/jacoco/jacocoTestDebugUnitTestReport/ $CIRCLE_ARTIFACTS/coverage