dt614037527 2016-09-21 14:01
浏览 36
已采纳

symfony中的单元测试实体何时使用测试db?

I know that you can test your models by specifying a temporary test database to be used by your test framework. Is this something that should be used always when testing a model? Or testing the functionality of just the class without persisting anything to the database is ok?

  • 写回答

1条回答 默认 最新

  • drvkf88226 2016-09-21 14:23
    关注

    It's really too general to say, if your model contains data manipulation logic, then it's not necessary to test against a real db. The logic can be validated by configuring fake data, calling the manipulation method and verifying the output. Your model must be designed in a way that supports this, though. If the model method is responsible for pulling data from the db, manipulating the data, and then persisting data it needs to be refactored to isolate those 3 distinct operations.

    Testing that your code works with an actual specific version of a database is necessary too, but most of your application logic should be able to validated at the unit test level.

    enter image description here

    Mike Cohn's test pyramid visually describes this concept. The majority of automated validation should occur at the lowest level possible. Integration tests (your app to mysql) are necessary but should only cover the actual integration and not excessively exercise application logic. This is because integration tests are more difficult to maintain and are slower because they use external resources. If you test on a shared environment (jenkins) then there are often operational issues in managing the resources.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算