流水应该在哪里放置单元测试? [英] Where should unit tests be placed in Meteor?

查看:98
本文介绍了流水应该在哪里放置单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以不受Meteor运行的测试的地方?

我刚刚开始我的第一个Meteor项目,并开始使用 Mocha should.js .尽管摩卡运行没有问题,但由于使用节点的require而不是__meteor_bootstrap__.require(

I just started my first Meteor project, and began by writing unit tests with Mocha and should.js. Though mocha runs without a problem, the tests prevent Meteor from starting up since it has issues using node's require instead of __meteor_bootstrap__.require (full error message).

话虽如此,流星不应该运行我的测试!根据流星文档,代码只能放在客户端,服务器或两者上.单元测试套件不属于这些类别,我

That being said, Meteor should not be running my tests! According to the Meteor documentation, code can only be placed on the client, server, or both. Unit test suites do no belong in these categories, and I am not the only person confused by Meteor's lack of a well-defined location for placing automated tests.

现在,我的测试保存在server/test/中,每个文件的内容都包装在块中:

Right now, my tests are kept in server/test/, with the contents of each file wrapped in the block:

if (typeof(Meteor) === 'undefined') { ... }

尽管这样做有效,但它并不优雅.您对使用Meteor应用程序构建测试还有其他建议吗?

While this works, it does not feel elegant. Do you have any other suggestions for structuring your tests with your Meteor app?

更新:代替Meteor文档中的明确说明,我遵循了设置文件夹约定(第4段),使用名为test的文件夹存储我的测试资产.后来我将其移至server/test,因为我不想将其加载到客户端上.

Update: in lieu of explicit instructions in the Meteor docs, I followed the Rails folder conventions (4th paragraph), using a folder called test for storing my testing assets. I later moved this to server/test since I did not want it loaded on the client.

推荐答案

将测试放置在tests/文件夹中.与Rails为此目的使用名为test的文件夹不同,Meteor为此文件夹名称使用了复数tests.

Place your tests in the tests/ folder. Unlike Rails, which uses a folder named test for this purpose, Meteor uses the plural tests for this folder name.

存储在名为"tests"的文件夹中的资产将被Meteor完全忽略;这些资产将不会加载到客户端服务器上.

Assets stored in a folder named "tests" will be completely ignored by Meteor; these assets will not be loaded on the client or server.

具有讽刺意味的是,我遇到了一个相反的问题的人,该人想要由Meteor客户端加载其测试

Ironically, I was tipped off by someone having the opposite issue who wants their tests loaded by the Meteor client.

这篇关于流水应该在哪里放置单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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