Magento - 单元测试

发布于 2024-12-04 03:15:56 字数 368 浏览 1 评论 0原文

我最近在 Magento 网站上遇到了一些问题,正在寻找一种方法来在任何给定点检查 Magento 网站的完整性。

单元测试是实现此目的的一种方法,但我认为编写大量测试来检查网站中的所有内容是否正常工作将是一项非常艰巨的工作。

参与单元测试和 magento 的任何人都可以就以下问题提供建议吗:

  1. 是否可以测试整个站点而不仅仅是自定义模块 - 所以一些测试的例子会很棒。
  2. 鉴于该网站与数据库密切相关 - 它会如何 可以在不干扰数据库的情况下全面测试站点
  3. 是否有更好的方法来自动检查站点的完整性 magento 网站

当我说诚信时,我的意思是网站上没有任何错误 - 运输、付款等都工作正常。

I have been having some problems with a Magento site recently and am looking for a way to check the integrity of a Magento site at any given point.

Unit Testing jumps out as one method of doing this but I would assume it would be a very big job to write a whole lot of tests to check everything in the site is working as it should.

Can anyone involved in unit testing and magento advise on the following:

  1. Is it possible to test the whole site and not just custom modules -
    is so some examples of tests would be amazing.
  2. Given that the site is heavily linked to the database - how would it
    be possible to fully test the site without disturbing the database
  3. Are there any better ways to automaticlly check the integrity of a
    magento site

When I say integrity i really mean that there are no faults on the site - shipping, payment etc are all working correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱人配狗天长地久 2024-12-11 03:15:56

这是一项艰巨的任务,但 Magento 社区成员已经解决了这个问题。

EcomDev_PHPUnit 模块提供了一个用于单元测试 Magento 的框架,但它不包含任何实际测试。它可以(并且已经)用于测试您自己开发的核心功能或模块。

EcomDev 模块的主要优点之一是它确实提供了 100% 的数据库隔离。它创建数据库结构的精确副本,然后使用固定装置(请参阅 manual) 将数据插入到这些表中以创建测试先决条件。这是强大的最佳实践,但确实需要大量设置。

您可以尝试使用 phpMyAdmin 将数据导出到 YAML 中,以准备创建固定装置。

另一种方法是为浏览器 UI 创建并自动化全面的 Selenium 测试套件。事实上,最好的解决方案是准备单元测试和 UI 测试,因为有些区域只能在一个功能域中进行测试。 Magento 的 Javascript 中内置了大量业务逻辑(例如所有的validation.js),PHPUnit 无法轻松测试,Selenium 是您的最佳选择。

早期对话关于创建单元测试存储库以涵盖核心功能,但请记住 Magento 2.0(计划于 2012 年)公布完整的测试覆盖范围

This is a big task, however there are Magento community members who have tackled it.

The EcomDev_PHPUnit module provides a framework for unit testing Magento, but it doesn't contain any actual tests. It could (and has) been used to test core functionality or modules that you have developed yourself.

One of the key advantages of the EcomDev module is that it does provide 100% isolation of your database. It creates an exact copy of your database structure, and then uses fixtures (see pg 6 of the manual) to insert data into those tables to create test pre-requisites. This is powerful and best practice, but does require quite a bit of setup.

You can try using phpMyAdmin to export data into YAML in readiness for creating fixtures.

The alternative is to create and automate a comprehensive Selenium test suite for the browser UI. In fact, the best solution is to prepare both unit and UI tests as there will be areas that can only be tested in one functional domain. There is a significant amount of business logic built into Magento's Javascript (all the validation.js for example) that PHPUnit can't easily test, Selenium is your best option here.

There have been early conversations about creating a repository of unit tests to cover the core functionality, however keep in mind that Magento 2.0 (planned for 2012) advertises complete test coverage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文