Testing using local files

前端 未结 2 1883
闹比i
闹比i 2020-12-11 02:05

I\'m looking for what best practice I should use when it comes to testing with Go using local files.

By using local files, I mean that in order to test functionality,

相关标签:
2条回答
  • 2020-12-11 02:44

    This is my current test setup:

    app/
       main.go
       main_test.go
       main_testdata
    
       package1/
         package1.go 
         package1_test.go 
         package1_testdata1
    
       package2/
         package2.go 
         package2_test.go 
         package2_testdata1
    

    All the test data that is specific to a single package, is placed within the directory of that package. Common test data that will be used by multiple packages are either placed in the application root or in $HOME.

    This set up works for me. Its easy to change the data and test, without having to do extra typing:

    vim package1_test_data1; go test app/package1

    0 讨论(0)
  • 2020-12-11 02:51

    A folder named testdata is usually used for this purpose as it is ignored by the go tool (see go help packages).

    0 讨论(0)
提交回复
热议问题