我的数据库没有立即插入
我正在尝试应用测试驱动开发来生成网页,但在使用我的数据库时遇到问题。我正在使用 Cake 1.1、PHP5 和 SimpleTest 进行单元测试。
我的问题是我有一个测试:
- 使用直接 SQL 语句插入一行
- 测试该行是否已插入(通过使用主程序中的函数)。
- 删除已插入的行。
步骤 1 和 3 都工作正常,但步骤 2 失败。
重要的是要认识到,如果我运行测试而不删除该行(我将其注释掉),然后再次运行测试,但首先消除步骤 1(再次简单地注释该行),并且测试顺利通过。
我还尝试在 PHPMyAdmin 中直接运行 SQL 语句(在编辑器中一个接一个),它们工作得很好。
I am a trying to apply Test Driven Development to producing a web page and am having trouble using my database. I am developing using Cake 1.1, PHP5 and SimpleTest to unit test.
My problem is that I have a test that:
- Inserts a row using a direct SQL statement
- Tests if that row was inserted (by using a function in my main program.)
- Deletes the row that was inserted.
Both steps 1 and 3 work fine but step 2 fails.
It's important to realize that if I run the test without deleting the row (I commented that out) and then ran the test again but first eliminating step 1 (once again simply commenting that line) and the test passed without a problem.
I also tried running the SQL statements directly (one after another in the editor) in PHPMyAdmin and they work perfectly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所有步骤都在同一个事务中执行吗?
如果不是,则在步骤 1 提交之前,步骤 2 无法看到步骤 1 的结果。
Are all steps executed in the same transaction?
When not, step 2 isn't able to see the result of step 1 until step 1 commits.
听起来确实像是您的插入发生在您尝试测试时尚未提交的事务内。
你能给出一些示例代码吗?
It does sound like your insert is happening inside a transaction that has not yet been committed when you attempt the test.
Can you give some sample code?
您确定要在步骤 1 中提交交易吗?
Are you sure you are committing the transaction in step 1?