Meteor 测试驱动开发 [英] Meteor test driven development

查看:19
本文介绍了Meteor 测试驱动开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在meteor 中进行测试驱动开发.

I don't see how to do test driven development in meteor.

我在文档或常见问题解答中没有看到任何地方提到它.我没有看到任何示例或类似内容.

I don't see it mentioned anywhere in documentation or FAQ. I don't see any examples or anything like that.

我看到有些软件包正在使用 Tinytest.

I see that some packages are using Tinytest.

我需要开发人员的回应,关于此的路线图是什么.类似的东西:

I would need response from developers, what is roadmap regarding this. Something along the lines of:

  • 可能,没有文档,自己想办法
  • meteor 的构建方式无法让您制作可测试的应用
  • 这是计划中的功能

推荐答案

更新 3:从 Meteor 1.3 开始,meteor 包括一个 测试指南,其中包含有关单元、集成、验收和负载测试的分步说明.

Update 3: As of Meteor 1.3, meteor includes a testing guide with step-by-step instructions for unit, integration, acceptance, and load testing.

更新 2:自 2015 年 11 月 9 日起,不再维护速度.Xolv.io 的工作重点是 ChimpMeteor 开发组必须选择官方测试框架.

Update 2: As of November 9th, 2015, Velocity is no longer maintained. Xolv.io is focusing their efforts on Chimp, and the Meteor Development Group must choose an official testing framework.

更新:VelocityMeteor 官方测试解决方案,截至 0.8.1.

Update: Velocity is Meteor's official testing solution as of 0.8.1.

目前关于使用 Meteor 进行自动化测试的文章并不多.我希望 Meteor 社区在正式文档中建立任何内容之前发展测试最佳实践.毕竟,本周流星达到了0.5,而且事情还在迅速变化.

Not much has been written about automated testing with Meteor at this time. I expect the Meteor community to evolve testing best-practices before establishing anything in the official documentation. After all, Meteor reached 0.5 this week, and things are still changing rapidly.

好消息:您可以使用 Node.js 测试工具 与流星.

The good news: you can use Node.js testing tools with Meteor.

对于我的 Meteor 项目,我用 Mocha 运行我的单元测试,使用 Chai 用于断言.如果您不需要 Chai 的完整功能集,我建议改用 should.js.我目前只有单元测试,不过你也可以用 Mocha 编写集成测试.

For my Meteor project, I run my unit tests with Mocha using Chai for assertions. If you don't need Chai's full feature set, I recommend using should.js instead. I only have unit tests at the moment, though you can write integration tests with Mocha as well.

务必将您的测试放在测试"中文件夹,以便 Meteor 不会尝试执行您的测试.

Be sure to place your tests in the "tests" folder so that Meteor does not attempt to execute your tests.

Mocha 支持 CoffeeScript,这是我为 Meteor 项目选择的脚本语言.这是一个示例 Cakefile,其中包含运行 Mocha 测试的任务.如果您在 Meteor 中使用 JS,请随意调整 Makefile 的命令.

Mocha supports CoffeeScript, my choice of scripting language for Meteor projects. Here's a sample Cakefile with tasks for running your Mocha tests. If you are using JS with Meteor, feel free to adapt the commands for a Makefile.

您的 Meteor 模型需要稍加修改才能将其自身暴露给 Mocha,这需要了解 Node.js 的工作原理.将每个 Node.js 文件视为在其自己的范围内执行.Meteor 会自动将不同文件中的对象相互公开,但普通的 Node 应用程序(如 Mocha)不会这样做.为了让 Mocha 可以测试我们的模型,使用以下 CoffeeScript 模式导出每个 Meteor 模型:

Your Meteor models will need a slight bit of modification to expose themselves to Mocha, and this requires some knowledge of how Node.js works. Think of each Node.js file as being executed within its own scope. Meteor automatically exposes objects in different files to one another, but ordinary Node applications—like Mocha—do not do this. To make our models testable by Mocha, export each Meteor model with the following CoffeeScript pattern:

# Export our class to Node.js when running
# other modules, e.g. our Mocha tests
#
# Place this at the bottom of our Model.coffee
# file after our Model class has been defined.
exports.Model = Model unless Meteor?

...并在 Mocha 测试的顶部,导入您要测试的模型:

...and at the top of your Mocha test, import the model you wish to test:

# Need to use Coffeescript's destructuring to reference
# the object bound in the returned scope
# http://coffeescript.org/#destructuring
{Model} = require '../path/to/model'

这样,您就可以开始使用 Meteor 项目编写和运行单元测试了!

With that, you can start writing and running unit tests with your Meteor project!

这篇关于Meteor 测试驱动开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆