Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing using local files

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, the application needs some local files, as the application reads from these files frequently.

I'm not sure if I should write temporary files myself just before running the tests using the ioutil package tempdir and tempfile functions, or create a test folder like so;

testing/...test_files_here
main.go
main_test.go

and then read from the contents inside

testing/...
like image 864
Miller Avatar asked Dec 08 '15 11:12

Miller


People also ask

What does testing on local mean?

Local Testing is the ability to test private or internal servers and local folders on the BrowserStack cloud. Private servers have no public access, and are generally internal or staging servers, or work in progress.

What is local software testing?

Localization Testing is a type of software testing that is performed to verify the quality of a product for a specific culture or locale. Localization testing is performed only on the local version of the product. Localization testing ensures that the application is capable enough to be used in that specific region.

What is file testing?

The file testing checklist is a very powerful fact-gathering tool used to verify that all needed files are included in the system being tested.


2 Answers

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

like image 133
Jeff Allen Avatar answered Oct 11 '22 19:10

Jeff Allen


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

like image 9
Anfernee Avatar answered Oct 11 '22 17:10

Anfernee