简体   繁体   English

从哪里运行单元测试有关系吗?

[英]Does it matter where to run unit tests from?

I have some tests with RSpec in a spec folder. 我在spec文件夹中使用RSpec进行了一些测试。 If I go to inside the main folder of my Rails project and do a bundle exec rspec all good. 如果我进入Rails项目的主文件夹并执行bundle exec rspec一切都很好。 They all pass. 他们都通过了。 But if I go inside a specific folder in that spec folder and want to run it like b undle exec this_file_spec.rb then I get errors. 但是,如果我去一个特定的文件夹在规范文件夹,并希望喜欢去运行它undle exec this_file_spec.rb然后我得到的错误。

Does it make a difference and we are not supposed to run it like that? 它会有所作为吗?我们不应该那样做吗?

NOTE: In my specs I AM calling some methods that are in a separate helper class in the spec folder. 注意:在我的规范中,我正在调用spec文件夹中单独的帮助程序类中的某些方法。 So maybe because I am not in that path for that helper method, it can't find it? 所以也许是因为我不在那种帮助方法的道路上,所以找不到它了?

It doesn't matter where your tests are run from if your tests are independent. 如果测试是独立的,则从何处运行测试都无关紧要。 I think your tests are dependent on the data setup by a different test. 我认为您的测试取决于其他测试的数据设置。 Make sure that your transactional fixtures are enabled. 确保已启用事务处理固定装置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM