DEV Community

Discussion on: Learn Go by writing tests

Collapse
 
quii profile image
Chris James

I have very limited experience with Ruby.

But the principles of TDD should still be helpful

When you say

unit test logging in via Google or FB

You probably dont want to unit test this. This sounds like if anything an integration test.

You need to think about what you want to test. You dont need to test a 3rd party as you (hopefully) trust it. Even if the test failed, what could you do? You cant edit their code!

What you can test is the way you interact with the 3rd party. You would probably want to read about "mocking" to achieve this.

In short you use something called a "Spy" instead of the "real" Google/FB thing you're using. Your test runs your code and then asks the Spy "Did Liz send through params x, y & z as I expect?" That should give you enough confidence that you're calling the 3rd party correctly.

I will eventually make a post about mocking things, watch this space.

Collapse
 
onecuteliz profile image
Elizabeth Jenerson

You are correct, Chris, that I'm looking for whether the right output came through as expected... Learned that's an integration test today. 🙂

I will definitely watch for that topic.
I've briefy read how some consider mocking the devil... I'm too junior to truly understand why but it'd be great if you could speak to that point ... Maybe folk's incorrect use of it makes mocking appear horrible or speaking to cases where it may not be best to mock. 🤷🏾‍♀️

Either way, thanks immensely, your explanations were wonderful and I'll keep an eye out.

Thread Thread
 
quii profile image
Chris James

Hi Liz

Hope this helps: dev.to/quii/learn-go-by-writing-te...