Per-test scope

For internal integration tests you will want to create Fake services to replace any services that access external systems (for example, databases or web services). Typically, the fake version service will have an extended interface that allows the test to provide fake data and the service will store that data in a simple in-memory data structures such as a Map. However, you will want those services to be re-set to a clean state at the start of every test.

Per-test scope is a new service scope that re-creates the service for each test.

You need to ensure that all your tests have TapestryTest as a superclass so that the scope is properly opened and closed for each test. Just follow the instructions for setting up JUnit3, JUnit4 or TestNG and you'll be fine.

Note that this is different to the built-in perthread scope - Tapestry will reset the perthread scope for every web request, but a test may use several requests. The new per-test scope allows test data to span multiple requests.

public class TestInfrastructureModule {
    public static void bind(ServiceBinder binder) {
        binder.bind(MyService.class, MyFakeService.class).scope(TestifyConstants.PERTEST);
    }
    
    
    @Scope(TestifyConstants.PERTEST)
    public static MyService buildMyService() {
        return new MyServiceImpl();
    }
}