public int ntests() { return method.getNumberOfTests(); }
private TestSuiteMethod createNewTestSuiteMethod(TestSuiteMethod testSuiteMethod) { IOpenMethod method = testSuiteMethod.getTestedMethod(); IOpenMethod newTargetMethod = getDeclaredMethod(method.getName(), method.getSignature().getParameterTypes()); TestSuiteMethod copy = new TestSuiteMethod(newTargetMethod, testSuiteMethod); copy.setModuleName(testSuiteMethod.getModuleName()); return copy; }
public TestSuiteMethod(IOpenMethod testedMethod, TestSuiteMethod copy) { super(copy.getHeader(), copy.getBoundNode()); db = copy.db; this.testedMethod = testedMethod; initProperties(copy.getMethodProperties()); this.runmethod = copy.isRunmethod(); this.testObjects = copy.getTestObjects(); this.descriptors = copy.getDescriptors(); this.setUri(copy.getUri()); }
public static boolean isMethodRunnedBy(IOpenMethod tested, IOpenMethod runner) { if (!(runner instanceof TestSuiteMethod)) { return false; } if (runner == tested) { return true; } IOpenMethod toTest = ((TestSuiteMethod) runner).getTestedMethod(); return toTest == tested && ((TestSuiteMethod) runner).isRunmethod(); }
private void updateDependency(BindingDependencies bindingDependencies) { IOpenMethod testedMethod = getTestedMethod(); if (testedMethod instanceof ExecutableRulesMethod || testedMethod instanceof OpenMethodDispatcher) { bindingDependencies.addMethodDependency(testedMethod, getBoundNode()); } }
public void write(TestUnitsResults result) throws Exception { TestSuite testSuite = result.getTestSuite(); String testName = testSuite.getTestSuiteMethod().getName(); String moduleName = testSuite.getTestSuiteMethod().getModuleName(); String suitName = "OpenL." + moduleName + "." + testName; String filename = "TEST-" + suitName + ".xlsx"; if (!dir.mkdirs() && !dir.exists()) { throw new IOException("Can't create folder '" + dir.getAbsolutePath() + "'."); } File file = new File(dir, filename); try (FileOutputStream outputStream = new FileOutputStream(file)) { new TestResultExport().export(outputStream, -1, result); } } }
private TestDescription[] initTestsAndIndexes() { DynamicObject[] testObjects = getTestObjects(); TestDescription[] tests = new TestDescription[testObjects.length]; indeces = new HashMap<>(tests.length); Map<String, Object> properties = getProperties(); Integer precision = null; if (properties != null && properties.containsKey(PRECISION_PARAM)) { precision = Integer.parseInt(properties.get(PRECISION_PARAM).toString()); } IOpenMethod testedMethod = getTestedMethod(); ColumnDescriptor[] descriptors = getDescriptors(); List<IOpenField> fields = createFieldsToTest(testedMethod, descriptors, precision); for (int i = 0; i < tests.length; i++) { tests[i] = new TestDescription(testedMethod, testObjects[i], fields, descriptors, db); tests[i].setIndex(i); indeces.put(tests[i].getId(), i); } return tests; }
/** * If tester is an instance of {@link TestSuiteMethod} and tested method object in tester is equal to tested we * consider tester is test for tested method. * * @param tester * @param tested * @return */ private static boolean isTestForMethod(IOpenMethod tester, IOpenMethod tested) { if (!(tester instanceof TestSuiteMethod)) { return false; } IOpenMethod toTest = ((TestSuiteMethod) tester).getTestedMethod(); return toTest == tested; }
/** * Checks if the tester is instance of {@link TestSuiteMethod}, if it has * any parameters for testing(see * {@link TestSuiteMethod#isRunmethodTestable()}) and if there is no errors * in it. * * @param tester instance of method that is considered to be a test. * @return true if tester is valid {@link TestSuiteMethod}. */ public static boolean isTester(IOpenMethod tester) { if (tester instanceof TestSuiteMethod) { try { TestSuiteMethod testSuiteMethod = (TestSuiteMethod) tester; return !testSuiteMethod.isRunmethod() && testSuiteMethod.isRunmethodTestable() && (testSuiteMethod.getSyntaxNode() == null || !testSuiteMethod.getSyntaxNode().hasErrors()); } catch (Exception e) { Logger log = LoggerFactory.getLogger(ProjectHelper.class); log.error(e.getMessage(), e); return false; } } return false; }
public static String createTestName(IOpenMethod testMethod) { IMemberMetaInfo mi = testMethod.getInfo(); TableSyntaxNode tnode = (TableSyntaxNode) mi.getSyntaxNode(); String name = TableSyntaxNodeUtils.getTableDisplayValue(tnode)[1]; if (testMethod instanceof TestSuiteMethod) { TestSuiteMethod testSuite = (TestSuiteMethod)testMethod; if (testSuite.isRunmethod()) { if (testSuite.nUnitRuns() < 1) { name += getTestAdditionalInfo(NO, RUNS); } else { name += getNumberOfTests(testSuite.nUnitRuns(), RUNS); } } else { if (testSuite.getNumberOfTests() < 1) { name += getTestAdditionalInfo(NO, TEST_CASES); } else { name += getNumberOfTests(testSuite.getNumberOfTests(), TEST_CASES); } } } return name; }
/** * Indicates if test method has any row rules for testing target table. * Finds it by field that contains * {@link TestMethodHelper#EXPECTED_RESULT_NAME} or * {@link TestMethodHelper#EXPECTED_ERROR} * * @return true if method expects some return result or some error. * * TODO: rename it. it is difficult to understand what is it doing */ public boolean isRunmethodTestable() { for (int i = 0; i < getNumberOfTests(); i++) { if (getTest(i).isExpectedResultDefined() || getTest(i) .isExpectedErrorDefined() || containsFieldsForSprCellTests( getTest(i).getTestObject().getFieldValues().keySet()) || (testedMethod instanceof Spreadsheet)) { return true; } } return false; }
public TestSuite(TestSuiteMethod testSuiteMethod, TestRunner testRunner) { this.testSuiteMethod = testSuiteMethod; tests = testSuiteMethod.getTests(); this.testRunner = testRunner; }
public TestSuiteMethod(IOpenMethod testedMethod, IOpenMethodHeader header, TestMethodBoundNode boundNode) { super(header, boundNode); db = boundNode.getDataBase(); this.testedMethod = testedMethod; initProperties(getSyntaxNode().getTableProperties()); runmethod = XlsNodeTypes.XLS_RUN_METHOD.toString().equals(getSyntaxNode().getType()); }
private void initializeTestData() { if (descriptors == null) { testObjects = (DynamicObject[]) getBoundNode().getField().getData(); descriptors = getBoundNode().getTable().getDataModel().getDescriptor(); } }
protected void addTestSuiteMethodsFromDependencies() { for (CompiledDependency dependency : this.getDependencies()) { for (IOpenMethod depMethod : dependency.getCompiledOpenClass().getOpenClassWithErrors().getMethods()) { if (depMethod instanceof TestSuiteMethod) { TestSuiteMethod testSuiteMethod = (TestSuiteMethod) depMethod; try { // Workaround for set dependency names in method while // compile if (testSuiteMethod.getModuleName() == null) { testSuiteMethod.setModuleName(dependency.getDependencyName()); } TestSuiteMethod newTestSuiteMethod = createNewTestSuiteMethod(testSuiteMethod); addMethod(newTestSuiteMethod); } catch (OpenlNotCheckedException e) { if (Log.isDebugEnabled()) { Log.debug(e.getMessage(), e); } addError(e); } } } } }
/** * Checks if test method doesn`t contain any error. * * @param testMethod test method * @return true if there is no errors in the test method. */ public static boolean noErrors(TestSuiteMethod testMethod) { return testMethod.getSyntaxNode().getErrors() == null || testMethod.getSyntaxNode().getErrors().length == 0; }
public String getUri() { return method.getSourceUrl(); }
private static String getTestInfo(IOpenMethod testMethod, int numberOfTests) { String info = null; if (testMethod instanceof TestSuiteMethod) { TestSuiteMethod testSuite = (TestSuiteMethod) testMethod; if (testSuite.isRunmethod()) { if (numberOfTests < 1) { info = "No runs"; } else if (numberOfTests == 1) { info = numberOfTests + " run"; } else { info = numberOfTests + " runs"; } } else { if (numberOfTests < 1) { info = "No test cases"; } else if (numberOfTests == 1) { info = numberOfTests + " test case"; } else { info = numberOfTests + " test cases"; } } } return info; } }
public String getName() { if (testSuiteMethod != null) { return testSuiteMethod.getName(); } else { return VIRTUAL_TEST_SUITE; } }
/** * Checks if the tester is instance of {@link TestSuiteMethod}, if it has any parameters for testing(see * {@link TestSuiteMethod#isRunmethodTestable()}) and if there is no errors in it. * * @param tester instance of method that is considered to be a test. * @return true if tester is valid {@link TestSuiteMethod}. */ public static boolean isTester(IOpenMethod tester) { return (tester instanceof TestSuiteMethod) && ((TestSuiteMethod) tester).isRunmethodTestable() && noErrors((TestSuiteMethod)tester); }