Search in sources :

Example 1 with TestCase

use of apet.testCases.TestCase in project abstools by abstools.

the class ABSUnitTestCaseTranslator method createTestSuiteForFunction.

/**
 * Create a test suite for testing a function.
 *
 * @param testCases
 * @param testInterface
 * @param className
 * @param functionName
 */
private void createTestSuiteForFunction(List<TestCase> testCases, InterfaceDecl testInterface, String functionName) {
    // create test class ([Suite])
    final ClassDecl testClass = translatorHelper.createTestClass(testInterface);
    module.addDecl(testClass);
    // find function under test
    FunctionDecl functionUnderTest = getDecl(model, FunctionDecl.class, new DeclNamePredicate<FunctionDecl>(functionName));
    final Access access = functionUnderTest.getTypeUse();
    importModules.add(functionUnderTest.getModuleDecl().getName());
    /*
		 * Test methods and Test cases are ordered that is,
		 * test case 1 is implemented by test method 1 and so on...
		 */
    for (int i = 0; i < testCases.size(); i++) {
        console("Generating test case " + i + "...");
        TestCase testCase = testCases.get(i);
        MethodImpl method = testClass.getMethod(i);
        functionBuilder.buildTestCase(testCase, testClass, method, access, functionName);
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) FunctionDecl(abs.frontend.ast.FunctionDecl)

Example 2 with TestCase

use of apet.testCases.TestCase in project abstools by abstools.

the class ABSUnitTestCaseTranslator method createTestSuiteForClassMethod.

/**
 * Create a test suite for testing a method.
 *
 * @param testCases
 * @param testInterface
 * @param className
 * @param methodName
 */
private void createTestSuiteForClassMethod(List<TestCase> testCases, InterfaceDecl testInterface, String className, String methodName) {
    // create test class ([Suite])
    final ClassDecl testClass = translatorHelper.createTestClass(testInterface);
    module.addDecl(testClass);
    // find class under test.
    ClassDecl classUnderTest = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(className));
    assert classUnderTest != null : "It should not be possible to not " + "find class under test";
    // find method under test.
    MethodImpl methodUnderTest = findMethodImpl(classUnderTest, new MethodNamePredicate(methodName));
    assert methodUnderTest != null : "It should not be possible to not " + "find method under test";
    // find interface of class under test.
    InterfaceDecl interfaceOfClassUnderTest = findInterfaceUnderTest(methodName, classUnderTest);
    if (interfaceOfClassUnderTest == null) {
    // this method is not exposed by any interface!
    }
    // return type
    MethodSig signature = methodUnderTest.getMethodSig();
    final Access access = signature.getReturnType();
    // add imports of class/interface under test
    importModules.add(classUnderTest.getModuleDecl().getName());
    importModules.add(interfaceOfClassUnderTest.getModuleDecl().getName());
    /*
		 * Test methods and Test cases are ordered that is,
		 * test case 1 is implemented by test method 1 and so on...
		 */
    for (int i = 0; i < testCases.size(); i++) {
        console("Generating test case " + i + "...");
        TestCase testCase = testCases.get(i);
        MethodImpl method = testClass.getMethod(i);
        methodBuilder.buildTestCase(testCase, testClass, method, access, methodName);
    }
}
Also used : MethodSig(abs.frontend.ast.MethodSig) AbsASTBuilderUtil.findMethodSig(abs.backend.tests.AbsASTBuilderUtil.findMethodSig) ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) MethodNamePredicate(abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Aggregations

AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)2 Access (abs.frontend.ast.Access)2 ClassDecl (abs.frontend.ast.ClassDecl)2 DeltaAccess (abs.frontend.ast.DeltaAccess)2 MethodImpl (abs.frontend.ast.MethodImpl)2 TestCase (apet.testCases.TestCase)2 MethodNamePredicate (abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate)1 AbsASTBuilderUtil.findMethodSig (abs.backend.tests.AbsASTBuilderUtil.findMethodSig)1 FunctionDecl (abs.frontend.ast.FunctionDecl)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 MethodSig (abs.frontend.ast.MethodSig)1