All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formos.tapestry.testify.testng.TapestryTest Maven / Gradle / Ivy

package com.formos.tapestry.testify.testng;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import com.formos.tapestry.testify.core.TapestryTester;

/**
 * TestNG base class for Tapestry tests. Note that test classes need to override
 * {@link #doSetUp()}. 
 * 

* I recommend that you create your own abstract class for you application tests * that subclasses this. You can then create a {@link TapestryTester} in that * class and store it in a static variable and also override * {@link #setUpForAllTestMethods()} for any other common setup. *

* For example: * *

 * public abstract class MyApplicationTest extends TapestryTest {
 *     private static final TapestryTester SHARED_TESTER = new TapestryTester(
 *             "pac.ka.ge", MyTestInfrastructureModule.class);
 * 
 *     public MyApplicationTest() {
 *         super(SHARED_TESTER);
 *     }
 * 
 *     @Override
 *     protected void setUpForAllTestClasses() throws Exception {
 *         MockitoAnnotations.initMocks(this);
 *     }
 * }
 * 
*/ public abstract class TapestryTest { protected final TapestryTester tester; /** * Creates a new instance using the given {@link TapestryTester}; you should * create this tester just once and share it across multiple tests, * for example by storing it in a static variable. * * @param tester * the tester to use (not null) */ public TapestryTest(TapestryTester tester) { assert tester != null; this.tester = tester; } /** * @deprecated Rename your method so that it overrides {@link #setUpForAllTestMethods()} */ @Deprecated protected void setUpForAllTestClasses() throws Exception { setUpForAllTestMethods(); } /** * See class javadoc for example: {@link TapestryTest} */ protected void setUpForAllTestMethods() throws Exception { // Do nothing by default } @BeforeClass(alwaysRun=true) public final void processInjectAnnotation() { tester.injectInto(this); } /** * Override {@link #doSetUp()} instead. */ @BeforeMethod(alwaysRun=true) public final void setUp() throws Exception { setUpForAllTestClasses(); doSetUp(); tester.collectForComponentsFrom(this); } /** * Override this instead of {@link #setUp()} */ protected void doSetUp() throws Exception { // Do nothing by default } @AfterMethod public final void tearDown() throws Exception { tester.endTest(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy