【问题标题】:mystyfing unit tests failing神秘的单元测试失败
【发布时间】:2011-05-20 09:20:52
【问题描述】:

我们正在使用 NHIbernate、.net 和 sql server2005。最令人困惑的是,使用相同的数据库,相同的单元测试,我的朋友没有任何类型的消息并且他们的所有测试都通过了,而我的朋友却有错误消息:

ERROR [TestRunnerThread] ADOExceptionReporter [(null)]- The DELETE statement conflicted with the REFERENCE constraint "FK_Project_Client". The conflict occurred in database "TestDev", table "dbo.Project", column 'ClientID'. The statement has been terminated. 13:10:02,656 ERROR [TestRunnerThread] SessionImpl [(null)]- could not synchronize database state with session NHibernate.ADOException: could not delete: [Client#875][SQL: DELETE FROM Client WHERE ID = ?] ---> System.Data.SqlClient.SqlException: The DELETE statement conflicted with the REFERENCE constraint "FK_Project_Client". The conflict occurred in database "TestDev", table "dbo.Project", column 'ClientID'.

在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔型 breakConnection)

在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,布尔型 breakConnection)

在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

在 System.Data.SqlClient.TdsParser.Run(运行行为 runBehavior,SqlCommand cmdHandler, SqlDataReader 数据流, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,运行行为运行行为,字符串 重置选项字符串)

在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior 运行行为、 布尔返回流,布尔异步)

在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior 运行行为、 布尔返回流,字符串方法, DbAsyncResult 结果)

在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult 结果,字符串方法名,布尔值 发送到管道)

在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

在 NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)

在 NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation 期待)

在 NHibernate.Persister.Entity.AbstractEntityPersister.Delete(对象 id,对象版本,Int32 j,对象 obj, SqlCommandInfo sql, ISessionImplementor 会话,对象[] 加载状态)

--- 内部异常堆栈结束 追踪---

在 NHibernate.Persister.Entity.AbstractEntityPersister.Delete(对象 id,对象版本,Int32 j,对象 obj, SqlCommandInfo sql, ISessionImplementor 会话,对象[] 加载状态)

在 NHibernate.Persister.Entity.AbstractEntityPersister.Delete(对象 id, 对象版本, 对象 obj, ISessionImplementor 会话)

在 NHibernate.Impl.ScheduledDeletion.Execute()

在 NHibernate.Impl.SessionImpl.Execute(IExecutable 可执行文件)

在 NHibernate.Impl.SessionImpl.ExecuteAll(IList 列表)

在 NHibernate.Impl.SessionImpl.Execute()

语句已终止。 像上面一样,我有各种其他测试失败并显示错误消息

无法同步数据库状态 与会话

知道我为什么会收到错误消息,有人知道吗?

【问题讨论】:

    标签: sql-server-2005 nhibernate nunit-2.5


    【解决方案1】:

    所有测试都是互斥的吗?那就是他们都互相运行independently 可能是一个测试干扰了另一个测试。

    如果你自己运行测试,你会遇到同样的问题吗?

    您是在自己的开发数据库上运行测试还是在共享开发数据库上运行测试?如果是你自己的,那么data和你的同事是一样的吗?

    我知道这不是一个严格的答案,并且有很多问题,但希望其中一个问题能够引导您找到解决方案。

    【讨论】:

    • 同意。听起来测试本身和/或可能是测试数据库并没有清理,而且测试实际上并不同步。进行始终失败的测试,然后从头开始完全重建最新的数据库并自行运行该测试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多