我应该如何测试整体可执行软件包? [英] How should I go about testing a monolithic executable package?

查看:68
本文介绍了我应该如何测试整体可执行软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个模块的整体式executable软件包. (我的意思是整体式"是指它的cabal文件中只有一个子句,即executable.)目前,它已通过shell脚本以黑盒方式进行了测试. .我以为我想为某些单独的功能编写单元测试,但是cabal并不同意:

I have a monolithic executable package with several modules. (What I mean by "monolithic" is that it only has one clause in its cabal file, and that is executable.) It is currently tested with shell scripts, in a black box manner. I thought I would like to write unit tests for some individual functions, but cabal does not agree:

% cabal new-test
cabal: Cannot test the package x-0.0.0.0 because none of the
components are available to build: the test suite 'x-test' is not
available because the solver did not find a plan that included the test suites

这是package.cabal的相关部分:

executable x
  ...
  other-modules: ...
  ...

test-suite x-test
    type: exitcode-stdio-1.0
    main-is: Test.hs
    build-depends: base, x
    hs-source-dirs: test

我的理解是,我应该将尽可能多的模块移到内部库中,这将使测试套件可以依赖它们.但是,我不确定维护者是否会赞成这种根本性的改变.有没有一种侵入性较小的方法?

My understanding is that I should move as many modules as possible to an internal library, which would make it possible for the test suite to depend on them. However, I am not sure the maintainers will approve of such radical change. Is there a less invasive way?

我的另一个担心是,就Main.hs子句中的Main.hs而言,并且我们不能将其导入到x-test中,其中的功能(至少是main)将不可用于测试.那么,除了外壳程序脚本之外,我应该如何测试这些功能?

My other concern is that, insofar as Main.hs is in the executable x clause, and we cannot import that into x-test, the functions therein (at the very least main) will be unavailable for testing. How should I go about testing these functions then, beside shell scripts?

推荐答案

完全可以将模块移至library节(如果不想公开这些模块,也可以将其移动到内部库节中).

It's completely okay to move modules to library stanza (or internal library stanza if you don't want to expose those modules).

除了shell脚本外,我应该如何进行测试?

How should I go about testing it, beside shell scripts?

在Haskell世界中,有一种惯例将所有内容(甚至是main函数)移动到library中,因此您的Main.hs看起来像这样:

There's a common practice in Haskell world to move everything (even main function) into library so your Main.hs would look like this:

module Main where

import MyLib as Lib (main)

main :: IO ()
main = Lib.main

通过这种方法,您可以通过Haskell单元测试库完全测试所有内容.

With this approach you can test completely everything via Haskell unit testing libraries.

但是,我不确定维护者是否会赞成这种根本性的改变.有没有一种侵入性较小的方法?

However, I am not sure the maintainers will approve of such radical change. Is there a less invasive way?

好吧,如果维护者关心他们的软件包,那么他们想要更好的测试就应该同意这种重构.

Well, if maintainers care about their package, they should agree to this refactoring if they want better testing.

这篇关于我应该如何测试整体可执行软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆