简体   繁体   English

编写test_that依赖于其他测试完成的测试

[英]Writing test_that tests that depend on other tests completing

I have written a series of test_that tests. 我已经编写了一系列test_that测试。 There is one test_that test which has a side-effect of creating a sqlite3 table. 有一个test_that测试具有创建sqlite3表的副作用。 The rest of the tests rely on this sqlite3 table. 其余测试均依赖此sqlite3表。 Is there a way to force this one test to run before any of the other tests do? 有没有一种方法可以强制此测试先于其他任何测试运行?

If you are using test_dir or test_package (otherwise you can just put the tests in the same file after the sqlite test), you can put your test that generates the table in its own file and use naming conventions for execution. 如果您使用的是test_dirtest_package (否则,您可以将测试仅放在sqlite测试之后的同一个文件中),则可以将生成表的测试放在其自己的文件中,并使用命名约定执行。 For example, inside tests/run.R you could have: 例如,在tests/run.R内部,您可以拥有:

test_file("tests/testthat/myspecialfile.R")   
test_dir("tests/testthat/")   # will run every file with a name starting with `test`

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

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