當前位置: 首頁>>代碼示例>>Java>>正文


Java TestContext.getTestMethod方法代碼示例

本文整理匯總了Java中org.springframework.test.context.TestContext.getTestMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java TestContext.getTestMethod方法的具體用法?Java TestContext.getTestMethod怎麽用?Java TestContext.getTestMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.test.context.TestContext的用法示例。


在下文中一共展示了TestContext.getTestMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: afterTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
@Override
public void afterTestMethod(TestContext testContext)  {
    Method method = testContext.getTestMethod();
    if (DataSetAnnotationUtils.isRun(method)) {
        try {
            MybatisTestProcessor mybatisTestProcessor = testContext.
                    getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
            boolean success = mybatisTestProcessor.compareResult(method);
            if (!success) {
                logger.info("Data test result : failure");
                Assert.fail();
            }
        } catch (EasyMallTestException e) {
            logger.error(e.getMessage(), e);
            Assert.fail(e.getMessage());
        }
    }
    logger.info("Data test result : success");
    MDC.clear();
}
 
開發者ID:easymall,項目名稱:easymall,代碼行數:21,代碼來源:JunitCaseListener.java

示例2: afterTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
@Override
public void afterTestMethod(TestContext testContext) {
    Method method = testContext.getTestMethod();
    if (DataSetAnnotationUtils.isRun(method)) {
        try {
            DataProcessor dataProcessor = testContext.
                    getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
            boolean success = dataProcessor.compareResult(method);
            if (!success) {
                logger.info("Data test result : failure");
                Assert.fail();
            }
        } catch (EasyTestException e) {
            logger.error(e.getMessage(), e);
            Assert.fail(e.getMessage());
        }
    }
    logger.info("Data test result : success");
    MDC.clear();
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:21,代碼來源:JunitCaseListener.java

示例3: initDatabase

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
/**
 * 初始化數據源
 *
 * @param testContext
 */
private void initDatabase(TestContext testContext) {
    SqlConfig.Database database = null;
    Class<?> testClass = testContext.getTestClass();
    SqlConfig sqlConfigInClass = testClass.getAnnotation(SqlConfig.class);
    if (sqlConfigInClass != null) {
        database = sqlConfigInClass.database();
    }
    Method method = testContext.getTestMethod();
    SqlConfig sqlConfigInMethod = method.getAnnotation(SqlConfig.class);
    if (sqlConfigInMethod != null) {
        database = sqlConfigInMethod.database();
    }
    if (database != null) {
        UnitTestDataSource.selectDataSource(database);
    }
}
 
開發者ID:warlock-china,項目名稱:wisp,代碼行數:22,代碼來源:UnitTestTransactionalTestExecutionListener.java

示例4: afterTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
/**
 * If a transaction is currently active for the supplied
 * {@linkplain TestContext test context}, this method will end the transaction
 * and run {@link AfterTransaction @AfterTransaction} methods.
 * <p>{@code @AfterTransaction} methods are guaranteed to be invoked even if
 * an error occurs while ending the transaction.
 */
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
	Method testMethod = testContext.getTestMethod();
	Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");

	TransactionContext txContext = TransactionContextHolder.removeCurrentTransactionContext();
	// If there was (or perhaps still is) a transaction...
	if (txContext != null) {
		TransactionStatus transactionStatus = txContext.getTransactionStatus();
		try {
			// If the transaction is still active...
			if ((transactionStatus != null) && !transactionStatus.isCompleted()) {
				txContext.endTransaction();
			}
		}
		finally {
			runAfterTransactionMethods(testContext);
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:28,代碼來源:TransactionalTestExecutionListener.java

示例5: setAlertCapability

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
private void setAlertCapability(TestContext context) {
    Method testMethod = context.getTestMethod();
    if (testMethod != null) {
        UnexpectedAlertCapability capability = testMethod.getAnnotation(UnexpectedAlertCapability.class);
        if (capability != null) {
            alertCapability.set(capability.capability());
        }
    }
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:10,代碼來源:SeleniumTestExecutionListener.java

示例6: beforeTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
    final String uuid = testCases.get();
    final Class<?> testClass = testContext.getTestClass();
    final Method testMethod = testContext.getTestMethod();
    final String id = getHistoryId(testClass, testMethod);

    final TestResult result = new TestResult()
            .withUuid(uuid)
            .withHistoryId(id)
            .withName(testMethod.getName())
            .withFullName(String.format("%s.%s", testClass.getCanonicalName(), testMethod.getName()))
            .withLinks(getLinks(testClass, testMethod))
            .withLabels(
                    new Label().withName("package").withValue(testClass.getCanonicalName()),
                    new Label().withName("testClass").withValue(testClass.getCanonicalName()),
                    new Label().withName("testMethod").withValue(testMethod.getName()),

                    new Label().withName("suite").withValue(testClass.getName()),

                    new Label().withName("host").withValue(getHostName()),
                    new Label().withName("thread").withValue(getThreadName())
            );

    result.getLabels().addAll(getLabels(testClass, testMethod));
    getDisplayName(testMethod).ifPresent(result::setName);
    getLifecycle().scheduleTestCase(result);
    getLifecycle().startTestCase(uuid);
}
 
開發者ID:allure-framework,項目名稱:allure-java,代碼行數:30,代碼來源:AllureSpring4.java

示例7: beforeTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
@Override
public void beforeTestMethod(TestContext testContext) {
    Method method = testContext.getTestMethod();
    if (DataSetAnnotationUtils.isRun(method)) {
        try{
            MybatisTestProcessor mybatisTestProcessor = testContext.
                    getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
            mybatisTestProcessor.insertPrepareData(method);
        } catch (EasyMallTestException e) {
            logger.error(e.getMessage(), e);
            Assert.fail(e.getMessage());
        }
    }
}
 
開發者ID:easymall,項目名稱:easymall,代碼行數:15,代碼來源:JunitCaseListener.java

示例8: beforeTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
@Override
public void beforeTestMethod(TestContext testContext) {
    Method method = testContext.getTestMethod();
    if (DataSetAnnotationUtils.isRun(method)) {
        try {
            DataProcessor dataProcessor = testContext.
                    getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
            dataProcessor.insertPrepareData(method);
        } catch (EasyTestException e) {
            logger.error(e.getMessage(), e);
            Assert.fail(e.getMessage());
        }
    }
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:15,代碼來源:JunitCaseListener.java

示例9: initTestData

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
private void initTestData(TestContext testContext) {
    List<String> sqlFiles = new ArrayList<String>();
    /**
     * 讀取測試類指定的sql文件
     */
    Class<?> testClass = testContext.getTestClass();
    SqlConfig sqlConfigInClass = testClass.getAnnotation(SqlConfig.class);
    if (sqlConfigInClass != null) {
        String[] sqlFilesInClass = sqlConfigInClass.sqlFiles();
        if (ArrayUtils.isNotEmpty(sqlFilesInClass)) {
            sqlFiles.addAll(Arrays.asList(sqlFilesInClass));
        }
    }
    /**
     * 讀取測試方法指定的sql文件
     */
    Method method = testContext.getTestMethod();
    SqlConfig sqlConfigInMethod = method.getAnnotation(SqlConfig.class);
    if (sqlConfigInMethod != null) {
        String[] sqlFilesInMethod = sqlConfigInMethod.sqlFiles();
        if (ArrayUtils.isNotEmpty(sqlFilesInMethod)) {
            sqlFiles.addAll(Arrays.asList(sqlFilesInMethod));
        }
    }
    /**
     * 執行sql
     */
    for (String sqlFile : sqlFiles) {
        LOGGER.info(String.format("execute sql file [%s]", sqlFile));
        this.executeSqlScript(testContext, sqlFile, false);
    }
}
 
開發者ID:warlock-china,項目名稱:wisp,代碼行數:33,代碼來源:UnitTestTransactionalTestExecutionListener.java

示例10: beforeTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
/**
 * If the test method of the supplied {@linkplain TestContext test context}
 * is configured to run within a transaction, this method will run
 * {@link BeforeTransaction @BeforeTransaction} methods and start a new
 * transaction.
 * <p>Note that if a {@code @BeforeTransaction} method fails, any remaining
 * {@code @BeforeTransaction} methods will not be invoked, and a transaction
 * will not be started.
 * @see org.springframework.transaction.annotation.Transactional
 * @see #getTransactionManager(TestContext, String)
 */
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
	final Method testMethod = testContext.getTestMethod();
	final Class<?> testClass = testContext.getTestClass();
	Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");

	TransactionContext txContext = TransactionContextHolder.removeCurrentTransactionContext();
	if (txContext != null) {
		throw new IllegalStateException("Cannot start a new transaction without ending the existing transaction.");
	}

	PlatformTransactionManager tm = null;
	TransactionAttribute transactionAttribute = this.attributeSource.getTransactionAttribute(testMethod, testClass);

	if (transactionAttribute != null) {
		transactionAttribute = TestContextTransactionUtils.createDelegatingTransactionAttribute(testContext,
			transactionAttribute);

		if (logger.isDebugEnabled()) {
			logger.debug("Explicit transaction definition [" + transactionAttribute + "] found for test context "
					+ testContext);
		}

		if (transactionAttribute.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
			return;
		}

		tm = getTransactionManager(testContext, transactionAttribute.getQualifier());
	}

	if (tm != null) {
		txContext = new TransactionContext(testContext, tm, transactionAttribute, isRollback(testContext));
		runBeforeTransactionMethods(testContext);
		txContext.startTransaction();
		TransactionContextHolder.setCurrentTransactionContext(txContext);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:49,代碼來源:TransactionalTestExecutionListener.java

示例11: detectDefaultScript

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
/**
 * Detect a default SQL script by implementing the algorithm defined in
 * {@link Sql#scripts}.
 */
private String detectDefaultScript(TestContext testContext, boolean classLevel) {
	Class<?> clazz = testContext.getTestClass();
	Method method = testContext.getTestMethod();
	String elementType = (classLevel ? "class" : "method");
	String elementName = (classLevel ? clazz.getName() : method.toString());

	String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName());
	if (!classLevel) {
		resourcePath += "." + method.getName();
	}
	resourcePath += ".sql";

	String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
	ClassPathResource classPathResource = new ClassPathResource(resourcePath);

	if (classPathResource.exists()) {
		if (logger.isInfoEnabled()) {
			logger.info(String.format("Detected default SQL script \"%s\" for test %s [%s]", prefixedResourcePath,
				elementType, elementName));
		}
		return prefixedResourcePath;
	}
	else {
		String msg = String.format("Could not detect default SQL script for test %s [%s]: "
				+ "%s does not exist. Either declare statements or scripts via @Sql or make the "
				+ "default SQL script available.", elementType, elementName, classPathResource);
		logger.error(msg);
		throw new IllegalStateException(msg);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:35,代碼來源:SqlScriptsTestExecutionListener.java

示例12: beforeOrAfterTestMethod

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
/**
 * Perform the actual work for {@link #beforeTestMethod} and {@link #afterTestMethod}
 * by dirtying the context if appropriate (i.e., according to the required modes).
 * @param testContext the test context whose application context should
 * potentially be marked as dirty; never {@code null}
 * @param requiredMethodMode the method mode required for a context to
 * be marked dirty in the current phase; never {@code null}
 * @param requiredClassMode the class mode required for a context to
 * be marked dirty in the current phase; never {@code null}
 * @throws Exception allows any exception to propagate
 * @since 4.2
 * @see #dirtyContext
 */
protected void beforeOrAfterTestMethod(TestContext testContext, MethodMode requiredMethodMode,
		ClassMode requiredClassMode) throws Exception {

	Assert.notNull(testContext, "TestContext must not be null");
	Assert.notNull(requiredMethodMode, "requiredMethodMode must not be null");
	Assert.notNull(requiredClassMode, "requiredClassMode must not be null");

	Class<?> testClass = testContext.getTestClass();
	Method testMethod = testContext.getTestMethod();
	Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
	Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");

	DirtiesContext methodAnn = AnnotatedElementUtils.findMergedAnnotation(testMethod, DirtiesContext.class);
	DirtiesContext classAnn = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class);
	boolean methodAnnotated = (methodAnn != null);
	boolean classAnnotated = (classAnn != null);
	MethodMode methodMode = (methodAnnotated ? methodAnn.methodMode() : null);
	ClassMode classMode = (classAnnotated ? classAnn.classMode() : null);

	if (logger.isDebugEnabled()) {
		String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After");
		logger.debug(String.format("%s test method: context %s, class annotated with @DirtiesContext [%s] "
				+ "with mode [%s], method annotated with @DirtiesContext [%s] with mode [%s].", phase, testContext,
			classAnnotated, classMode, methodAnnotated, methodMode));
	}

	if ((methodMode == requiredMethodMode) || (classMode == requiredClassMode)) {
		HierarchyMode hierarchyMode = (methodAnnotated ? methodAnn.hierarchyMode() : classAnn.hierarchyMode());
		dirtyContext(testContext, hierarchyMode);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:45,代碼來源:AbstractDirtiesContextTestExecutionListener.java

示例13: setUseProxy

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
private void setUseProxy(TestContext context) {
    Method testMethod = context.getTestMethod();
    if (testMethod != null && testMethod.getAnnotation(BrowserMobProxy.class) != null) {
        useProxy.set(true);
    }
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:7,代碼來源:SeleniumTestExecutionListener.java

示例14: setNeedToRestart

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
private void setNeedToRestart(TestContext context) {
    Method testMethod = context.getTestMethod();
    if (testMethod != null && testMethod.getAnnotation(NeedRestartDriver.class) != null) {
        isNeedToRestart.set(true);
    }
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:7,代碼來源:SeleniumTestExecutionListener.java

示例15: setUseFireBug

import org.springframework.test.context.TestContext; //導入方法依賴的package包/類
private void setUseFireBug(TestContext context) {
    Method testMethod = context.getTestMethod();
    if (testMethod != null && testMethod.getAnnotation(FireBug.class) != null) {
        isUseFireBug.set(true);
    }
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:7,代碼來源:SeleniumTestExecutionListener.java


注:本文中的org.springframework.test.context.TestContext.getTestMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。