Saturday, April 27, 2024
HomeGolangTransferring checks to a sub folder and importing package deal important -...

Transferring checks to a sub folder and importing package deal important – Getting Assist


Hello.

I constructed an utility within the root folder with *.go package deal set to important.

I additionally construct some take a look at *_test.go in the identical ‘root’ listing.

So anyway I moved ALL my *_test.go information to a sub folder ‘take a look at’. I modified the package deal names to ‘take a look at’ however the take a look at code can not entry the code within the root (important) dir.

Is there a method of importing …/. as in a relative ‘up one stage’ as a result of I can not make it work.

I spent hours making a go.mod. Do I require a go.mod file and all that means, ‘go mod tidy’ ‘requires’ with package deal names and so on.

What’s the greatest/easiest approach to isolate the checks from the code.

I’ve to say that I discover the modules construction very complicated.

Please assist

Stuart

A take a look at for a package deal lives in the identical folder because the package deal it checks. That is the way it works in go.

2 Likes

Hello @stuartdd,

In additon to @NobbZ’s recommendation, be aware that package deal important can’t be imported by different packages.

If you wish to maintain the foundation dir clear from _test.go information, take into account factoring out all code that has checks from the primary package deal to a library package deal.

Your important package deal will then include just some startup code and glue code that may not be appropriate for unit testing anyway.

3 Likes

Okay. Thanks. I cannot fear about it then.

I wished to do it correctly and now I do know what correctly is :blush:

Regards

Stuart

Thanks for the recommendation however I’ve seen the any declarations within the take a look at file turn out to be seen in all information.

For instance a take a look at methodology calling a ‘take a look at’ utility methodology with the intention to save replication within the take a look at code.

I made the error of making a shut(t *testing.T, title string) methodology within the take a look at file. This triggered errors after I closed a channel utilizing shut(c). It was a little bit unusual on the time as VSCode highlighted the error however compiled it anyway.

It took me a while to kind it as a result of the code compiled however broke when it ran!

I’ve the measure of it now however I can see a possibility for introducing errors into code. Is there a greater method?

Stuart

This subject was mechanically closed 90 days after the final reply. New replies are not allowed.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments