简体   繁体   English

Eliom框架中的单元测试

[英]Unit Tests in the Eliom Framework

I am building a new project using Eliom and having trouble setting up a compilation process for unit tests using OUnit. 我正在使用Eliom构建一个新项目,并且无法使用OUnit为单元测试设置编译过程。

I have two files: 我有两个文件:

 Js_Client_Code.eliom - contains all of the client side code
 Project.eliom - contains all of the server side code (including opening Js_Client_Code.eliom)

I have set up the files in this way so that I can run unit tests on Js_Client_Code.eliom without using ocsigenserver . 我已经以这种方式设置了文件,这样我就可以在不使用ocsigenserver情况下在Js_Client_Code.eliom上运行单元测试。

This is my current makefile for the tests: 这是我当前用于测试的makefile:

 test: prep unit_tests     

 prep:
     eliomc -infer Js_Client_Code.eliom
     js_of_eliom -linkall -a Js_Client_Code.eliom -o file_a.cma
     eliomc -a -linkall Js_Client_Code.eliom -o file_b.cma

 # Code is here to move the cma files back to the parent directory, since they are written to _client/ and _server/ by default

 unit_tests:
     ocamlfind ocamlc -thread -syntax camlp4o -package ounit,js_of_ocaml.syntax \
     -linkpkg -g -o UnitTests file_a.cma file_b.cma unit_tests.ml

Running make test in the shell produces 在shell中运行make test会产生

 File "unit_tests.ml", line 1:
 Error: Error while linking file_a.cma(Js_Client_Code):
 Reference to undefined global `Eliom_client'

Am I misunderstanding the Eliom/Js_of_ocaml compilation process, or just going about this the wrong way? 我是否误解了Eliom / Js_of_ocaml编译过程,或者只是以错误的方式解决这个问题?

You're not linking the eliom libraries at all, so of course it's missing all the external modules. 你根本没有链接eliom库,所以当然它缺少所有的外部模块。

Honestly, I don't think you'll manage to unit test modules that depends on eliom that way. 老实说,我认为你不会设法单独测试依赖于eliom的模块。 It would probably be easier to unit test the non-eliom part indivdually, and do end-to-end browser-based tests (there are lot's of framework for that). 可能更容易单独测试非eliom部分,并进行端到端的基于浏览器的测试(有很多框架)。

If you really want to try, there are explanations on eliom (or ocsigenserver)'s manual to link statically. 如果你真的想尝试,有关于eliom(或ocsigenserver)手册的静态链接的解释。

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

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