我在运行OUnit测试时遇到了困难,主要是因为我对沙丘和OUnit都很陌生。dune在我运行dune runtest时会抱怨
File "test/dune", line 4, characters 13-14:
Error: Library "f" not found.
Hint: try: dune external-lib-deps --missing @runtest以下是项目结构:
├── dune
├── f.ml # This is the source file.
└── test
├── dune
└── f_test.ml # This is the test.我是dune
(executable
(name f))我是test/dune
(test
(name f_test)
(libraries oUnit f)) ; <- `f` here causes problems.我可以看到,出现错误是因为沙丘不知道f.ml,因此不知道沙丘文件中的f。
如何使沙丘编译f.ml的方式使test/dune了解我在test/f_test.ml中使用的f库?如何正确运行单元测试?
发布于 2018-11-15 17:48:53
一种可能性是将f拆分为私有库和可执行文件,然后测试拆分库。
编辑:
例如,可以将项目结构更新为
├── dune
├── f.ml # f only contains the I/O glue code.
├── lib
| ├── dune
| └── a.ml # a implements the features that need to be tested.
└── test
├── dune
└── test.ml # This is the test.用dune
(executable (name main) (libraries Lib)) 为了测试,test/dune
(test (name test) (libraries Lib oUnit))最后是lib/dune
(library (name Lib))使用此设置,可以使用dune runtest运行测试。
https://stackoverflow.com/questions/53317459
复制相似问题