This post is the first in a WIP project called learn-go-with-tests.
From the README
Explore the Go language by writing tests
Get a grounding wi...
For further actions, you may consider blocking this person and/or reporting abuse
Wow super great post. Thanks Chris!
Wo Wo Wo... Well done Chris!
This blog helps me out in solving my coding assignments on C, C++, Java, Python in my graduation level.
Cheers
Alex Martin
Content/Copy Writer
EssayCorp: essaycorp.com
What a lovely comment
This was awesome. Thanks, Chris!!
Now, turning attention to the audience - if I needed a peer to help w/ creating tests:
I understand why to test, how to set up my tests (using Rspec to test RoR), but I can't wrap my brain on how to unit test logging in via Google or FB. 😟
If inappropriately posted totally delete and tell me where to go 🤪
I have very limited experience with Ruby.
But the principles of TDD should still be helpful
When you say
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.
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.
Hi Liz
Hope this helps: dev.to/quii/learn-go-by-writing-te...
Just seeing this now, but really enjoyed this. As someone who is looking to pick up Go as another language, I found your style of explanation really easy to follow and frankly hammered home some concepts that were a little fuzzy to me.
I hope you'll keep writing. Thanks!
Thanks for sharing the knowledge Chris.
I spent some hours reading godoc, that I have never heard before.
Loved the format of learning a new language such as go through TDD, because I learned testing and syntax in parallel.
Great post.
I think that t.ErrorF must be t.Errorf (We are calling the ErrorF method on our t...)
Thanks for sharing
Thanks, and good spot :)
Unreal experience, diving is my favorite thing, now I will officially list it in one of my hobbies. redball4.us
Just read it, great post! :-)
Still a bummer there's no "default argument value" in Go, but I understand the point, especially in a strictly typed system.
You can still cheat with structs and default values though
Thanks!
Im not sure it being statically typed is a reason for no default values, kotlin, scala and many others have it.
I guess in Go's eyes they value explicitness over developer convenience in this case. That's not to say either is right or wrong, just an opinion on language design
I hate to sound negative, but want to caution that anyone who is planning to learn Go should take a look at this page:
github.com/ksimka/go-is-not-good
Some time ago I read all critic articles about Go. And now I have to say that most of them are about of matching of programming habits of authors. Most of them are pretty subjective.
By example, common place for Go critics is absence of generics. But actually some generics are not so generics as they named. They sometimes provide some requirements to object in container. Then what's difference against Go interfaces? So...
I also miss some things in Go, but I prefer to leave a place to grow. Go is pretty young.
I am not going to really engage with this but I had a browse of the lists and i saw
Is a pretty interesting reason not to use a language ;)
That point definitely sounds ridiculous, however, there are genuine criticisms on that page, it's better for any newbee to skim through the list once.
Yeah, some of Go's criticism is definitely on point but I guess advantages and drawbacks have to be considered in each language.
I wouldn't pick Go as my first programming language :-)
I know this is very subjective. But to me, this was one of the best posts I've read on Dev.to.
Thanks for the post, Chris!!!
Thanks!
great post. Thanks Chris!
and i am puzzled by the granularity of test. For example, whether we needed a test for greetingPrefix when we have had TestHello already.
It's interesting because Go does let you test private functions but I think it is best to avoid doing that.
The reason being is you should try to avoid testing the underlying algorithm in tests. What I mean by that is test outcomes, not the way it is done.
Why is that important?
A lot of code bases suffer when developers want to refactor, but end up having to change a load of test code so it feels like a pain.
But the very definition of refactoring should be that the behaviour of the code doesnt change! If you are testing your algorithms you are making refactoring harder.
Coming back to our example, "greetingPrefix" is just an internals of our public API. Let's pretend I did write a test, but then decided I actually preferred to not have it as a separate function (for some reason). I would have to change test code, even though I'm only refactoring.
I've waffled on a bit there, but i hope it makes sense!
It help a lot that the behaviour of the code is more importance than the way how it is done.
Usually, we reduce the internal coupling through the interface(public API), so the behavior of the interface is crucial, and the test should focus on the interface to ensure it behaves as expected. At the angle of efficiency in testing, it is not necessary to pay much attention to the internal implementation.
I am very interested in this topic, thanks! paperminecraft.io
Okay, it was interesting and informative, but it would be even better if you have included real-life examples. getaway shootout
Any luck with finding a song which you were looking for? Use Shazam mate.
dogeminer2.org
My boss is a cool guy, he is chill all the time and it seems like he hardly cares about anything(rocketleagueunblocked.com).
It was horrible and disgusting, I still can’t believe how bad I performed on the stage.
idle breakout
Oh cool, tomorrow we will have yet another One Piece episode, can't wait till tomorrow.
When did you last have a deep conversation with someone? I believe it was a long time ago.
Ahahaha yeah, it will do the job, now I see how you managed to achieve it.
Drift Hunters Unblocked
Stop listing your issues here(dogeminer2unblocked.com), use forum instead or open ticket….
I have to admit, I had no idea what Coub was a couple of days ago, now I’m addicted to it and can’t stop watching it. cupcake 2048
Don’t be afraid of modern technologies, I know things change fast, but it is totally okay and natural. Scribbleio
So everyone else around me is getting vacation except me, is there something wrong with me? fireboyandwatergirlunblocked.co
Flooding with SMS messages my phone from the morning... Start of the day is awful.
alchemygame.io
Amazing but I love to see more live coding test for learning please do some more real time based code so i can understand even better regards take my exam online for me
Value your time, don’t waste it on arguing with stupid people.
Fly or Die