Repository: authorjapps/zerocode
Pull request #86 (2018-06-03 05:43:15)

ISS-83 # Test text validated


Patch:
diff --git a/src/main/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunner.java b/src/main/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunner.java
index 65869e87..1f8ded40 100644
--- a/src/main/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunner.java
+++ b/src/main/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunner.java
@@ -34,6 +34,7 @@ public class ZeroCodeLoadRunner extends ParentRunner<TestMapping> {
     @Override
     protected List<TestMapping> getChildren() {
         validateAnnotationPresence();
+        validateTestMethod();
         return Arrays.asList(testClass.getAnnotationsByType(TestMapping.class));
     }
 
@@ -90,4 +91,15 @@ public class ZeroCodeLoadRunner extends ParentRunner<TestMapping> {
 
     }
 
+    private void validateTestMethod() {
+        String errMessage = " was invalid, please re-check and pick the correct test method to load.";
+        try {
+            TestMapping methodMapping = testClass.getAnnotation(TestMapping.class);
+            errMessage = "Mapped test method `" + methodMapping.testMethod() + "`" + errMessage;
+            methodMapping.testClass().getMethod(methodMapping.testMethod());
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(errMessage + e);
+        }
+    }
+
 }


Test patch:
diff --git a/src/test/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunnerTest.java b/src/test/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunnerTest.java
index 7901d84d..e3b2030c 100644
--- a/src/test/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunnerTest.java
+++ b/src/test/java/org/jsmart/zerocode/core/runner/parallel/ZeroCodeLoadRunnerTest.java
@@ -22,6 +22,7 @@ public class ZeroCodeLoadRunnerTest {
     ZeroCodeLoadRunner zeroCodePackageRunner;
     ZeroCodeLoadRunner runnerNoTestMapping;
     ZeroCodeLoadRunner runnerMultiTestMapping;
+    ZeroCodeLoadRunner runnerInvalidTestMapping;
 
     @LoadWith("load_config_test.properties")
     @TestMapping(testClass = JunitRestTestSample.class, testMethod = "testGetCallToHome_pass")
@@ -30,7 +31,7 @@ public class ZeroCodeLoadRunnerTest {
 
     }
 
-    // @TestMapping not present for unit test
+    // @TestMapping not present to check exception
     @LoadWith("load_config_test.properties")
     @RunWith(ZeroCodeLoadRunner.class)
     public class ExampleRunnerWithoutMappingTest {
@@ -43,11 +44,18 @@ public class ZeroCodeLoadRunnerTest {
     public class ExampleRunnerMultiMappingTest {
     }
 
+    @LoadWith("load_config_test.properties")
+    @TestMapping(testClass = JunitRestTestSample.class, testMethod = "dodgyAndInvalidTestMethod")
+    @RunWith(ZeroCodeLoadRunner.class)
+    public class ExampleRunnerInvalidMethodMappingTest {
+    }
+
     @Before
     public void initializeRunner() throws Exception {
         zeroCodePackageRunner = new ZeroCodeLoadRunner(ExampleRunnerTest.class);
         runnerNoTestMapping = new ZeroCodeLoadRunner(ExampleRunnerWithoutMappingTest.class);
         runnerMultiTestMapping = new ZeroCodeLoadRunner(ExampleRunnerMultiMappingTest.class);
+        runnerInvalidTestMapping = new ZeroCodeLoadRunner(ExampleRunnerInvalidMethodMappingTest.class);
     }
 
     @Test
@@ -69,6 +77,12 @@ public class ZeroCodeLoadRunnerTest {
         List<TestMapping> children = runnerMultiTestMapping.getChildren();
     }
 
+    @Test
+    public void testPair_invalidTestMethodMappingException() {
+        expectedException.expectMessage("Mapped test method `dodgyAndInvalidTestMethod` was invalid, please re-check and pick");
+        List<TestMapping> children = runnerInvalidTestMapping.getChildren();
+    }
+
     @Test
     public void testPair_size() {
         List<TestMapping> children = zeroCodePackageRunner.getChildren();