Commit d5d1ee76 authored by Matyáš Latner's avatar Matyáš Latner

#653 Ability to run desktop iTest bundle like gradle task

parent 29ece419
import groovy.io.FileType
/*
* Copyright (C) 2016 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
*
......@@ -105,6 +107,42 @@ task releaseJar(type: Jar) {
}
}
task runITestBundle(dependsOn: iTestJar) {
doLast {
int testsCount = 0;
int successfulTestsCount = 0;
def iTestOutputPath = "${libsDir}/iTest_results/"
def iTestOutputFile = new File(iTestOutputPath)
if (iTestOutputFile.exists()) {
println "[iTest] REMOVING OLD iTest OUTPUT DIRECTORY"
iTestOutputFile.deleteDir()
}
new File(project(':itest').bundleFilePath).eachLine { iTestName ->
testsCount++;
runItest(iTestName)
}
iTestOutputFile.traverse(type : FileType.FILES, nameFilter: ~/OK_.*\.log/) { iTestLog ->
successfulTestsCount++;
}
if (testsCount != successfulTestsCount) throw new GradleException("Failed to complete all iTests! Check iTest log files in: \'${iTestOutputPath}\'")
}
}
def runItest(String iTestName) {
println "[iTest] STARTING TEST: " + iTestName
def stdout = new ByteArrayOutputStream()
exec {
ignoreExitValue true
workingDir libsDir
commandLine 'java', '-jar', tablexiaAppName + "-iTest-" + tablexiaVersionName + ".jar", iTestName
standardOutput = stdout
}
println "[iTest] TEST: " + iTestName + " FINISHED"
}
debugJar.dependsOn classes
debugJar.dependsOn(':util:checksum:runChecksum')
releaseJar.dependsOn classes
......
......@@ -17,4 +17,8 @@
*/
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = ["src/"]
\ No newline at end of file
sourceSets.main.java.srcDirs = ["src/"]
project.ext {
bundleFilePath = "${project.projectDir}/iTestBundle.txt"
}
\ No newline at end of file
TestScenarioSpecial
NewUserScenario
\ No newline at end of file
......@@ -20,6 +20,7 @@ package cz.nic.tablexia.testing;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.PixmapIO;
import com.badlogic.gdx.math.Rectangle;
......@@ -82,8 +83,11 @@ import cz.nic.tablexia.util.ui.dialog.components.TwoButtonContentDialogComponent
* Created by frantisek on 19.4.16.
*/
public abstract class AbstractTestScenario implements Runnable {
private static final String TESTING_FOLDER = "automated-testing/";
private static final String LOG_FILE_EXT = ".log";
private static final String OUTPUT_DIRECTORY_NAME = "iTest_results/";
private static final FileHandle OUTPUT_DIRECTORY_FILE_HANDLE = Gdx.files.local(OUTPUT_DIRECTORY_NAME);
private static final String LOG_FILE_EXT = ".log";
private static final String SCREENSHOT_EXTENSION = ".png";
public static final String NAME_FOR_TESTS = "TestDetektiv";
public static final int AGE_FOR_TESTS = 12;
......@@ -113,15 +117,15 @@ public abstract class AbstractTestScenario implements Runnable {
private static final String TEST_STATUS_FAIL = "FAIL";
private static final String TEST_STATUS_PROCESSING = "PROCESSING";
private Thread testThread;
private File currentLogFile = null;
private Thread testThread;
private File currentLogFile = null;
/**
* Screenshot counter
*/
private static int screenNum = 1;
private List<String> logMessages = new ArrayList<String>();
private List<String> logMessages = new ArrayList<>();
private ExecutionTimeout timeout;
private boolean inDebugMode = false;
......@@ -201,8 +205,8 @@ public abstract class AbstractTestScenario implements Runnable {
if(currentLogFile == null) {
GregorianCalendar calendar = new GregorianCalendar();
nameOfTheTest = getClass().getSimpleName();
File outputDirectory = Gdx.files.external(TESTING_FOLDER).file();
if (outputDirectory.exists() || outputDirectory.mkdir()) {
FileHandle outputDirectory = prepareOutputDirectory();
if (outputDirectory != null) {
currentTestName = nameOfTheTest + "_" + new SimpleDateFormat(DATE_FORMAT_FOR_LOGFILE_NAME, Locale.US).format(calendar.getTime());
currentLogFile = prepareLogFileForStatus(TEST_STATUS_PROCESSING);
if (currentLogFile == null) {
......@@ -219,8 +223,20 @@ public abstract class AbstractTestScenario implements Runnable {
return true;
}
private FileHandle prepareOutputDirectory() {
FileHandle outputDirectory = OUTPUT_DIRECTORY_FILE_HANDLE;
if (outputDirectory != null && (outputDirectory.exists() || outputDirectory.file().mkdir())) {
return outputDirectory;
}
return null;
}
private File prepareLogFileForStatus(String status) {
return Gdx.files.external(TESTING_FOLDER + status + "_" + currentTestName + LOG_FILE_EXT).file();
FileHandle outputDirectory = prepareOutputDirectory();
if (outputDirectory == null) {
return null;
}
return outputDirectory.child("/" + status + "_" + currentTestName + LOG_FILE_EXT).file();
}
private void finishTest() {
......@@ -613,26 +629,31 @@ public abstract class AbstractTestScenario implements Runnable {
new Thread(new Runnable() {
@Override
public void run() {
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGB888);
ByteBuffer bb = pixmap.getPixels();
bb.clear();
bb.position(0);
for (int pixel : screen) {
int r = (pixel & 0xff000000) >> 24;
int g = (pixel & 0x00ff0000) >> 16;
int b = (pixel & 0x0000ff00) >> 8;
bb.put((byte) r);
bb.put((byte) g);
bb.put((byte) b);
}
PixmapIO.writePNG(Gdx.files.external(TESTING_FOLDER + currentTestName + "_" + screenNum++ + ".png"), pixmap);
if (finishCallback != null)
finishCallback.run();
}
}).start();
}
});
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGB888);
ByteBuffer bb = pixmap.getPixels();
bb.clear();
bb.position(0);
for (int pixel : screen) {
int r = (pixel & 0xff000000) >> 24;
int g = (pixel & 0x00ff0000) >> 16;
int b = (pixel & 0x0000ff00) >> 8;
bb.put((byte) r);
bb.put((byte) g);
bb.put((byte) b);
}
FileHandle outputDirectory = prepareOutputDirectory();
if (outputDirectory == null) {
Log.err(getClass(), "Cannot create output directory for logs!");
return;
}
PixmapIO.writePNG(outputDirectory.child("/" + currentTestName + "_" + screenNum++ + SCREENSHOT_EXTENSION), pixmap);
if (finishCallback != null) {
finishCallback.run();
}
}
}).start();
}
});
}
/**
......@@ -1145,7 +1166,9 @@ public abstract class AbstractTestScenario implements Runnable {
fw.write(message);
}
fw.close();
currentLogFile.delete();
if (!currentLogFile.delete()) {
Log.err(getClass(), "Cannot delete temporary log file!");
}
} catch(IOException e) {
Log.err(getClass(), "Cannot rewrite log file!", e);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment