Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

AbstractTransactionalSpringContextTests Class

Convenient superclass for tests that should occur in a transaction, but normally will roll the transaction back on the completion of each test.

For a list of all members of this type, see AbstractTransactionalSpringContextTests Members .


[Visual Basic]
Public MustInherit Class AbstractTransactionalSpringContextTests
    Inherits AbstractDependencyInjectionSpringContextTests
public abstract class AbstractTransactionalSpringContextTests : AbstractDependencyInjectionSpringContextTests

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.


This is useful in a range of circumstances, allowing the following benefits:

This class is typically very fast, compared to traditional setup/teardown scripts.

If data should be left in the database, call the

method in each test. The "DefaultRollback" property, which defaults to "true", determines whether transactions will complete by default.

It is even possible to end the transaction early; for example, to verify lazy loading behavior of an O/R mapping tool. (This is a valuable away to avoid unexpected errors when testing a web UI, for example.) Simply call the

method. Execution will then occur without a transactional context.


method may be called after a call to
if you wish to create a new transaction, quite independent of the old transaction. The new transaction's default fate will be to roll back, unless
is called again during the scope of the new transaction. Any number of transactions may be created and ended in this way. The final transaction will automatically be rolled back when the test case is torn down.

Transactional behavior requires a single object in the context implementing the IPlatformTransactionManager interface. This will be set by the superclass's Dependency Injection mechanism. If using the superclass's Field Injection mechanism, the implementation should be named "transactionManager". This mechanism allows the use of this superclass even when there's more than one transaction manager in the context.

This superclass can also be used without transaction management, if no IPlatformTransactionManager object is found in the context provided. Be careful about using this mode, as it allows the potential to permanently modify data. This mode is available only if dependency checking is turned off in the AbstractDependencyInjectionSpringContextTests superclass. The non-transactional capability is provided to enable use of the same subclass in different environments.


Namespace: Spring.Testing.NUnit

Assembly: Spring.Testing.NUnit (in Spring.Testing.NUnit.dll)

See Also

AbstractTransactionalSpringContextTests Members | Spring.Testing.NUnit Namespace