douzhang8144 2015-09-04 10:55
浏览 150

使用ginkgo / gomega测试Go应用程序时测试文件的正确结构

My Go app(restfull api service) is growing and i decided to use testing. My choise is Ginkgo/Gomega.

Learning site (http://onsi.github.io/ginkgo/#getting-started-writing-your-first-test) i found that to start test you need

  1. goto the package
  2. ginkgo bootstrap

This will create file [your_package]_suite_test in root of package folder. It's Ok.

But then if i want to test some feature or file or package i need again goto the folder and ginkgo generate [test_name] which will create stub test file here.

So, in one moment we will have many messy: files of our app and testing files together in one folder. For example, server.go, server_test.go, auth.go, auth_test.go, and so on.

I want to searate app files and test files. For example i want to create a folder tests in root package and place all tests here. So, when i need to test app i can run go test ./tests

Is it correct pattern to use Ginkgo/Gomega with separate tests folder?

Thanks.

  • 写回答

1条回答 默认 最新

  • donglunzai4288 2016-04-03 00:13
    关注

    In Go you can run all tests of a given project with a single command regardless of where your test files are located. In a terminal, change to your project base directory and run:

    $ go test ./...
    

    In my Go projects I usually have a separate Bash script that will do this for me. You can can place it, for instance, in bin/run_tests.sh with the following contents:

    #!/bin/bash -e
    time go test ./... | grep -v '^?'
    

    Make this file executable and then run it:

    $ ./bin/run_tests.sh
    

    I don't have a separate test folder. Judging by most Go projects I see around what developers are going for is having the test file in the same directory where the file being tested is located.

    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了