【问题标题】:Data access Integration Testing...how do you do it?数据访问集成测试...你是怎么做的?
【发布时间】:2010-09-23 10:00:19
【问题描述】:
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);
        }
    }
}

【问题讨论】:

  • 有什么问题 - 如何测试上面的代码?
  • 您能否详细说明您要达到的目标?
  • 你能给我们更多的信息吗?你的问题太笼统了。查看catb.org/~esr/faqs/smart-questions.html,了解如何提出好问题的技巧。它会增加您获得答案的机会。

标签: .net testing tdd continuous-integration integration


【解决方案1】:

我可以看到你在一个事务中进行战术测试以在测试后回滚。

我个人从头开始,为测试创建表,然后将其删除。另一种常见的技术是将数据库恢复到已知状态 - 尽管我建议这表明如果测试依赖于数据库中的大量状态,则它们的范围太广。

我为 PHP 写过这篇文章,但我更经常在 .NET 中工作。

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

【讨论】:

    猜你喜欢
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 2015-01-16
    • 2010-09-11
    • 2011-12-18
    • 1970-01-01
    相关资源
    最近更新 更多