Commit b2eadb5f authored by Aneta Steimarova's avatar Aneta Steimarova

#352 added info when test runs without parameter test class name; removed...

#352 added info when test runs without parameter test class name; removed unused inner class in AbstractTestScenario
parent e2eb07b9
......@@ -19,19 +19,16 @@ package cz.nic.tablexia.android;
import android.os.Bundle;
import com.badlogic.gdx.Gdx;
import cz.nic.tablexia.testing.TestRunner;
import cz.nic.tablexia.util.Log;
/**
* Created by frantisek on 13.4.16.
*/
public class AndroidITestLauncher extends AndroidLauncher {
private String testClassName = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
String testClassName = null;
Bundle extras = this.getIntent().getExtras();
if ( extras != null ) {
if (extras.containsKey("testClassName")) {
......@@ -39,18 +36,12 @@ public class AndroidITestLauncher extends AndroidLauncher {
}
}
super.onCreate(savedInstanceState);
if(testClassName==null){
Log.err(getClass(), "No parameter has been given. Please, launch activity with parameter -e testClassName <TEST_CLASS_NAME>.");
Gdx.app.exit();
}
runTest(testClassName);
}
@Override
protected void runTest(){
private void runTest(String testClassName){
TestRunner testRunner = new TestRunner(tablexia);
if(testClassName!=null) {
testRunner.runTest(testClassName);
}
testRunner.runTest(testClassName);
}
}
......@@ -43,12 +43,6 @@ public class AndroidLauncher extends AndroidApplication {
protected Tablexia tablexia;
/*
* Method for running tests
*
*/
protected void runTest(){}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -77,7 +71,6 @@ public class AndroidLauncher extends AndroidApplication {
HAS_SOFT_BACK_BUTTON,
savedInstanceState == null,
Build.SERIAL), config);
runTest();
}
public void post(Runnable r) {
......
......@@ -17,10 +17,7 @@
package cz.nic.tablexia.desktop;
import com.badlogic.gdx.Gdx;
import cz.nic.tablexia.testing.TestRunner;
import cz.nic.tablexia.util.Log;
/**
* Created by frantisek on 15.4.16.
......@@ -28,11 +25,10 @@ import cz.nic.tablexia.util.Log;
public class DesktopITestLauncher{
public static void main(String[] arg) {
TestRunner testRunner = new TestRunner(DesktopLauncher.initTablexia());
if (arg == null || arg.length == 0) {
Log.err("DesktopITestLauncher", "No parameter has been given! Please, launch the application with parameter <TEST_CLASS_NAME>.");
Gdx.app.exit();
new TestRunner();
} else {
TestRunner testRunner = new TestRunner(DesktopLauncher.initTablexia());
String testClassName = arg[0];
testRunner.runTest(testClassName);
}
......
......@@ -30,10 +30,8 @@ public class IOSITestLauncher extends IOSLauncher {
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
boolean result = super.didFinishLaunching(application, launchOptions);
if(testClassName != null) {
TestRunner testRunner = new TestRunner(tablexia);
testRunner.runTest(testClassName);
}
TestRunner testRunner = new TestRunner(tablexia);
testRunner.runTest(testClassName);
return result;
}
......
......@@ -187,7 +187,6 @@ public abstract class AbstractTestScenario implements Runnable {
@Override
public void uncaughtException(Thread t, Throwable e) {
logError("UncaughtException: " + e.getMessage());
ApplicationBus.getInstance().publishAsync(new TestFinished(getClass().getSimpleName()));
}
});
testThread.start();
......@@ -218,7 +217,6 @@ public abstract class AbstractTestScenario implements Runnable {
*/
public void finishTest() {
testStatus();
ApplicationBus.getInstance().publishAsync(new TestFinished(getClass().getSimpleName()));
testThread.interrupt();
Gdx.app.exit();
}
......@@ -1090,7 +1088,7 @@ public abstract class AbstractTestScenario implements Runnable {
try {
SWIPED_LOCK.wait();
} catch (InterruptedException e) {
logError("Cannot wait for swiping to thophy! InterruptedException: " + e.getMessage());
logError("Cannot wait for swiping to trophy! InterruptedException: " + e.getMessage());
stopTheTest();
}
}
......@@ -1169,21 +1167,6 @@ public abstract class AbstractTestScenario implements Runnable {
finishTest();
}
/**
* Event fired when actual test has finished
*/
public static class TestFinished implements ApplicationBus.ApplicationEvent {
private final String finishedtestName;
private TestFinished(String testName) {
finishedtestName = testName;
}
public String getFinishedtestName() {
return finishedtestName;
}
}
protected User createUser(){
return createUser(NAME_FOR_TESTS, AGE_FOR_TESTS , GENDER_FOR_TESTS, AVATAR_FOR_TESTS, SIGNATURE_FOR_TESTS);
}
......
......@@ -35,6 +35,10 @@ public class TestRunner {
public TestRunner(Tablexia tablexia) {
this.tablexia = tablexia;
createListOfTests();
}
private void createListOfTests(){
listOfTests.add(NewUserScenario.class);
listOfTests.add(TestScenarioSpecial.class);
listOfTests.add(TestScenarioHallOfFameRobberyTrophies.class);
......@@ -47,9 +51,32 @@ public class TestRunner {
listOfTests.add(TestScenarioHallOfFameRunesTrophies.class);
listOfTests.add(TestScenarioHeapOfTrophies.class);
}
public void runTest(String testClassName){
public TestRunner(){
System.out.println("No parameter has been given! Please, launch the application with parameter\n\tdesktop: <TEST_CLASS_NAME>\n\tAndroid: -e testClassName <TEST_CLASS_NAME>");
createListOfTests();
String tests = testsToString();
System.out.println("Registred tests (<TEST_CLASS_NAME>):" + tests);
}
private String testsToString(){
String tests = null;
for(Class<? extends AbstractTestScenario> testClass : listOfTests){
if(testClass.getSimpleName().equals(testClassName)) {
if(tests==null) tests = "\n\t" + testClass.getSimpleName();
else tests += "\n\t" + testClass.getSimpleName();
}
return tests;
}
public void runTest(String testClassName){
if(testClassName==null){
Log.err(getClass(), "No parameter has been given! Please, launch the application with parameter\n\tdesktop: <TEST_CLASS_NAME>\n\tAndroid: -e testClassName <TEST_CLASS_NAME>");
String tests = testsToString();
Log.info(getClass(),"Registred tests (<TEST_CLASS_NAME>):" + tests);
}
else {
for (Class<? extends AbstractTestScenario> testClass : listOfTests) {
if (testClass.getSimpleName().equals(testClassName)) {
try {
AbstractTestScenario test = (AbstractTestScenario) ClassReflection.getConstructor(testClass, Tablexia.class).newInstance(tablexia);
Log.info(getClass(), "[ RUNNING TEST : " + testClass.getSimpleName() + " ]");
......@@ -59,8 +86,9 @@ public class TestRunner {
}
return;
}
}
Log.err(getClass(), "Test class \"" + testClassName + "\" does not exist!");
}
Log.err(getClass(), "Test class \"" + testClassName + "\" does not exist!" );
Gdx.app.exit();
}
}
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