使用沙丘运行OUnit测试

时间:2018-11-15 10:34:19

标签: ocaml ounit ocaml-dune

我在运行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中使用的f库的方式编译test/f_test.ml?如何正确运行单元测试?

1 个答案:

答案 0 :(得分:3)

一种可能性是将result.RecognitionResult.Where(s => !string.IsNullOrEmpty(s.Text) && s.Text == "lawyer"); 拆分为私有库和可执行文件,然后测试拆分后的库。

编辑:

例如,项目结构可以更新为

.FirstOrDefault()

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运行测试。

相关问题