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

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

问题描述

我看不到如何在流星中进行测试驱动的开发.

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:

  • 可能,没有文档,请自己弄清楚
  • 流星不是以可以制作可测试应用的方式构建的
  • 这是计划中的功能

推荐答案

更新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将工作重点放在黑猩猩

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.

更新:速度

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项目,我使用 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.

请务必将测试放入测试"中文件夹,这样流星就不会尝试执行测试.

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测试的任务.如果您将JS与Meteor一起使用,请随时为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文件都视为在其自己的范围内执行.流星会自动将不同文件中的对象彼此公开,但是普通的Node应用程序(如Mocha)则不会这样做.要使我们的模型可通过Mocha进行测试,请

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!

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

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