Commit 68acc755 authored by Aneta Steimarova's avatar Aneta Steimarova

#352 Starting app iTest with parametr changed - now it runs with test class name as parameter

parent 5f29c041
......@@ -28,25 +28,19 @@ import cz.nic.tablexia.util.Log;
* Created by frantisek on 13.4.16.
*/
public class AndroidITestLauncher extends AndroidLauncher {
private int testID;
private boolean givenParameter;
private String testClassName = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
Bundle extras = this.getIntent().getExtras();
if ( extras != null ) {
if (extras.containsKey("testID")) {
testID = extras.getInt("testID");
givenParameter = true;
} else {
givenParameter = false;
if (extras.containsKey("testClassName")) {
testClassName = (String) extras.get("testClassName");
}
}else {
givenParameter = false;
}
super.onCreate(savedInstanceState);
if(!givenParameter){
Log.err(getClass(), "No parameter has been given/ Unknown test. Please, launch activity with parameter --ei testID <TEST_ID>.");
if(testClassName==null){
Log.err(getClass(), "No parameter has been given. Please, launch activity with parameter -e testClassName <TEST_CLASS_NAME>.");
Gdx.app.exit();
}
}
......@@ -54,8 +48,8 @@ public class AndroidITestLauncher extends AndroidLauncher {
@Override
protected void runTest(){
TestRunner testRunner = new TestRunner(tablexia);
if(givenParameter) {
testRunner.runTest(testID);
if(testClassName!=null) {
testRunner.runTest(testClassName);
}
}
......
......@@ -17,6 +17,7 @@
package cz.nic.tablexia.testing;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.badlogic.gdx.utils.reflect.ReflectionException;
......@@ -34,31 +35,32 @@ public class TestRunner {
public TestRunner(Tablexia tablexia) {
this.tablexia = tablexia;
listOfTests.add(NewUserScenario.class); //0
listOfTests.add(TestScenarioSpecial.class); //1
listOfTests.add(TestScenarioHallOfFameRobberyTrophies.class); //2
listOfTests.add(TestScenarioHallOfFamePursuitTrophies.class); //3
listOfTests.add(TestScenarioHallOfFameKidnappingTrophies.class); //4
listOfTests.add(TestScenarioHallOfFameNightWatchTrophies.class); //5
listOfTests.add(TestScenarioHallOfFameShootingRangeTrophies.class); //6
listOfTests.add(TestScenarioHallOfFameInTheDarknessTrophies.class); //7
listOfTests.add(TestScenarioHallOfFameCrimeSceneTrophies.class); //8
listOfTests.add(TestScenarioHallOfFameRunesTrophies.class); //9
listOfTests.add(TestScenarioHeapOfTrophies.class); //10
listOfTests.add(NewUserScenario.class);
listOfTests.add(TestScenarioSpecial.class);
listOfTests.add(TestScenarioHallOfFameRobberyTrophies.class);
listOfTests.add(TestScenarioHallOfFamePursuitTrophies.class);
listOfTests.add(TestScenarioHallOfFameKidnappingTrophies.class);
listOfTests.add(TestScenarioHallOfFameNightWatchTrophies.class);
listOfTests.add(TestScenarioHallOfFameShootingRangeTrophies.class);
listOfTests.add(TestScenarioHallOfFameInTheDarknessTrophies.class);
listOfTests.add(TestScenarioHallOfFameCrimeSceneTrophies.class);
listOfTests.add(TestScenarioHallOfFameRunesTrophies.class);
listOfTests.add(TestScenarioHeapOfTrophies.class);
}
public void runTest(int testID){
if(testID>=0 && testID<listOfTests.size()) {
Class<? extends AbstractTestScenario> testClass = listOfTests.get(testID);
try {
AbstractTestScenario test = (AbstractTestScenario) ClassReflection.getConstructor(testClass, Tablexia.class).newInstance(tablexia);
Log.info(getClass(), "[ RUNNING TEST " + testID + ": " + testClass.getSimpleName() + " ]");
test.runTest();
} catch (ReflectionException e) {
Log.err(getClass(), "Cannot create instance of test " + testClass.getSimpleName() + "! " + e.getMessage());
}
}
else{
Log.err(getClass(), "Test with ID " + testID + " does not exist!" );
public void runTest(String testClassName){
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() + " ]");
test.runTest();
} catch (ReflectionException e) {
Log.err(getClass(), "Cannot create instance of test " + testClass.getSimpleName() + "! " + e.getMessage());
}
return;
}
}
Log.err(getClass(), "Test class \"" + testClassName + "\" does not exist!" );
Gdx.app.exit();
}
}
......@@ -30,16 +30,11 @@ 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 app with parameter <TEST_ID>.");
Log.err("DesktopITestLauncher", "No parameter has been given! Please, launch the application with parameter <TEST_CLASS_NAME>.");
Gdx.app.exit();
} else {
try {
int testID = Integer.parseInt(arg[0]);
testRunner.runTest(testID);
} catch (NumberFormatException e) {
Log.err("DesktopITestLauncher", "Given parameter is not an integer! " + e.getMessage());
Gdx.app.exit();
}
String testClassName = arg[0];
testRunner.runTest(testClassName);
}
}
}
......@@ -24,15 +24,15 @@ import cz.nic.tablexia.testing.TestRunner;
public class IOSITestLauncher extends IOSLauncher {
private static int testID = Integer.MAX_VALUE;
private static String testClassName = null;
@Override
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
boolean result = super.didFinishLaunching(application, launchOptions);
if(testID != Integer.MAX_VALUE) {
if(testClassName != null) {
TestRunner testRunner = new TestRunner(tablexia);
testRunner.runTest(testID);
testRunner.runTest(testClassName);
}
return result;
}
......@@ -40,7 +40,7 @@ public class IOSITestLauncher extends IOSLauncher {
public static void main(String[] argv) {
if(argv.length > 0) {
try {
testID = Integer.parseInt(argv[0].trim());
testClassName = argv[0].trim();
} catch (NumberFormatException e) {
e.printStackTrace();
}
......
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