Data Integration Testing ... how do you do it?

public class RollBack : OnMethodBoundaryAspect // or another AOP for meth interception
{
    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    {
        try
        {
            ServiceConfig cfg = new ServiceConfig();
            cfg.Transaction = TransactionOption.RequiresNew;
            cfg.TrackingAppName = "Application Unit Tests";
            cfg.TransactionDescription = "Application Unit Tests Transaction";
            cfg.TransactionTimeout = 0x2710;
            ServiceDomain.Enter(cfg);
        }
        catch (Exception exception)
        {
            Console.WriteLine("Could not enter into a new transaction:\n" + exception);
        }
    }

    public override void OnExit(MethodExecutionEventArgs eventArgs)
    {
        try
        {
            if (ContextUtil.IsInTransaction)
            {
                ContextUtil.SetAbort();
            }
            ServiceDomain.Leave();
        }
        catch (Exception exception)
        {
            Console.WriteLine("Could not leave an existing transaction:\n" + exception);
        }
    }
}

      

0


source to share


1 answer


I see that you are tactically validating the transaction to rollback after testing.

I personally start from scratch and create tables for the test and delete them afterwards. Another common technique is to restore the database to a known state - although I would assume that this indicates tests that are too large if they rely on a lot of state in the database.



I've written about this for PHP, but most often I work in .NET.

http://www.stevefenton.co.uk/Content/Blog/Date/201110/Blog/Database-Integration-Testing-With-Enhance-PHP/

0


source







All Articles