DEV Community

Discussion on: It's Been Three Months Since My First Go LoC 🤓 🎓

Collapse
 
rhymes profile image
rhymes

Hi Boris, happy you're liking Go so far!

(un)-marshalling
If someone knows a better solution, don't hesitate!

I think the best solution is validation. I used govalidator successfully in a project.

You can do stuff like:

type Ticket struct {
  Id        int64     `json:"id"`
  FirstName string    `json:"firstname" valid:"required"`
}

Writing unit tests is the worst part of my developer journey in Golang

It took me a while to get testing right in my first project but Go has really powerful testing chops. I'm starting to like test tables and you can easily debug test cases from VSCode.

With Go, there is no equivalent of PHPUnit or JUnit that allows to quickly mock any dependency.

testify seems nice, haven't tried it yet

A couple of posts about unit testing in Go that I read:

It seems like the official Go doc (which is great) is quite the only available resource, except posts on StackOverflow.

There are resources around, you just have to find them. A good place to start are the newsletters Golang Weekly and Master the World of Golang.

What is also confusing is that if you google something like "go + ", you won't get many results. You'll have more luck with "golang + ".

Ah ah yes. Naming it Go was a bad move, it's too late for that

Have fun!

Collapse
 
biros profile image
Boris Jamot ✊ /

I will have a look at govalidator.
I already use testify for assertions, but it's not designed for mocking.

Thanks for your support, I'll have a look at your resources!

Collapse
 
rhymes profile image
rhymes

What about this part of testify's documentation? github.com/stretchr/testify#mock-p...

It doesn't work?

Thread Thread
 
biros profile image
Boris Jamot ✊ /

I didn't know about mocking with testify. It seems to be working similarly to gomock.
The problem is that the mocks have to be generated manually and to be maintained along with your codebase.

Thread Thread
 
rhymes profile image
rhymes

Yeah, fortunately I don't use mocking that much

Collapse
 
gbafana25 profile image
Gareth M.

They should've just called it Gopher, like GopherCon right?