douying2243 2018-10-15 10:33
浏览 39
已采纳

测试不同包装中的方法

While writing test cases I found 2 problems:

  1. There are 3 test files out of which one_test.go and two_test.go can be added to server_suites_test.go and it runs fine. But the functions of three_point_one_test.go cannot be added into server_suites_test.go because _test.go cannot be imported.

  2. one_test.go and two_test.go use gRPC client object which is created by server_test.go. Actually, server_test.go creates a gRPC server and a client and this client is used by the other test cases. Currently three_point_one_test.go cannot access this client. So to solve this issue I'm creating client every time this test is run.

Project Structure(incomplete BTW!)

> tree /f
Folder PATH listing for volume Windows
Volume serial number is 1C92-17A5
C:.
└───data
    │   one.go
    │   one_test.go
    │   two.go
    │   two_test.go
    │   server.go
    │   server_suites_test.go
    │   server_test.go
    │   
    └───three
            three_point_one.go
            three_point_one_test.go

server_suites_test.go

package data

import (
    "testing"
    "someproj/three"
)

func TesOne(t *testing.T) {
    t.Run("One", testOne) //from one_test.go
}

func TestTwo(t *testing.T) {
    t.Run("Two", testTwo) //from two_test.go
}

// Below code cannot be compiled -START
func TestThreePointOne(t *testing.T) {
    t.Run("ThreePointOne", three.TestThreePointOne) //cannot import this function
}
// Below code cannot be compiled -END

Is there any way to add other tests present in children packages into the test suite?

  • 写回答

1条回答 默认 最新

  • douyi1084 2018-10-15 10:53
    关注

    Is there any way to add other tests present in children packages into the test suite?

    No.

    Tests are not part of the package. As you can import only whole packages and the tests are not part of it you simply cannot. And stop thinking about "child packages": There are no such things. All packages are equal and their filesystem location does not matter (except internal and vendor).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?