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,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());
}
}