167 likes
·
2.6K reads
27 comments
Great post Katy. I struggle with this myself, tending to work on smaller projects and succumbing to laziness! Important for software students to have this demonstrated to them as early as possible as part of real projects 👌🏻
I know unit testing is not the fun or sexy part of software development.
But it's worth it when you see all those green ticks... you know life will be ok. 😆
Thanks for the comment Jon, it should be taught to CS students really.
Amazing first article, Katy. Testing is on my to-learn list. It's not something that I've come across in my learning so far, it wasn't in the courses I did. I'll get to it soon though as I think it will be a big plus when applying for jobs.
Thanks Debbie ☺️ it will definitely help you stand out, especially as a junior.
Yay first article! The problem is that not every company takes unit testing seriously enough to have it as part of their daily workflow. And new developers tend to leave it until last or skip it altogether because it is not exciting to do.
It's true, and so it's up to us developers to hammer the point home that tests are valuable, and we want them in our code base!
Thanks for the comment 😊
Hey, Katie. Great article. Do you have any recommendation on how to determine what exactly to test in a component / class? Could the acceptance criteria of a story contribute to this?
Hey Florin, thanks for the comment!
While AC should provide the great basis for feature testing, often they are too high level for unit tests. E.g. if your AC is to create an endpoint which POSTs a new blog post for example, you would have multiple classes to create this, and multiple sets of unit tests which will all test small parts of the flow but not the overarching feature. So the AC might be "When I submit a blog post to my endpoint, then I can view the blog post on the website"
The unit tests will be more granular like "Given I submit text to the controller, When I call Post, Then the Add To Database method is called" - and you would only be testing the Controller object here with all other dependencies mocked.
It's hard to explain without a better example but hopefully I can write up some in the near future. Hope that helps!
Great article! My internship this summer was my first experience with unit testing and I definitely see the benefit now. Saved so much time even though at first it doesn’t seem like it.
Thanks for commenting Chris! I'm glad you're starting off somewhere which has already instilled the important of unit tests! It will only be positive for the future 😁
Hello all,
This was a great post. It is important to do the unit test, Junit test, and practice running the code after the completion of a line. QA is always number one. Lastly, make sure you run "Hello World" before every project.
Thanks for commenting!
Great words right there! I have just started learning some basic testing for a React project of mine and I am starting to see its potential 💪🏼 As you said, it might not be the sexiest thing in programming, but it should be well considered for any Solid software structure! Thanks for the article 🙏🏼
A debt of gratitude is in order for imparting decent data to us. I like your post and all you share with us is forward-thinking and very enlightening, High Profile Escorts in Bangalore I might want to bookmark the page so I can come here again to understand you, as you have worked effectively
Great Article! Now I may be a bad dev. But I have 0 idea what a unit test is. 🙃
Hopefully you have a slightly better idea now!
Hi Katy, great post. I enjoyed the reading; It shows that you know what you are talking about.
Although I have some clarifications to make (I hope you don't mind)
A unit test is the smallest test you can do on your code.
That depends. When you work with TDD or TCR you write even smaller tests (micro tests) and all together they make up a unit test.
The perfect unit test class will only test ONE class.
Many people associate that idea with "unit", which must be a class, function, or module. It is actually a behavior in which the behavior could be modeled by the interaction of multiple classes or functions. It doesn't necessarily mean having a to test just one class, module, or function.
Hey Rodrigo, thanks for the comment.
My article is intended to summarise unit testing, rather than go into a lot of detail.
In general, unit tests are written to test one class at a time.
Unit tests are a complete waste of time. I'm so sick of zealots and evangelists like you propagating the myth that they actually make a difference. If you write tests, you are wasting your boss's time and money. I hear developers declare, "whoa, I wouldn't feel safe if my code wasn't back my tests". This is such rubbish. I have never seen a unit test save the day. I've never heard the words, "Whoa, that was a close one, lucky we had that unit test." They are a pest and a maintenance burden. Unit tests, just say NO.
I'm sorry you feel like this - I have seen unit tests stop bugs getting introduced many times.
Indeed I have been in situations where I would have said "If we have had unit tests, these regressions would never happened" and the customer would have been much more happy.
"Software Engineering", the only engineering discipline where testing is optional!
I wonder how many people would want the same philosophy in Civil or Mechanical Engineering.
From my experience, I've found that unit tests have other values that aren't promoted as much. The value of "preventing bugs" isn't as valuable as the following:
- Unit tests provide a living documentation of the requirements.
- Unit tests are a powerful design tool when TDD is done. It enables the developer to work with the interface before the implementation. Thus, allowing them to empathize with code maintainers before the code becomes a mess.
I think the name "Unit Test" is unfortunate. For whatever reason, our industry sees "testing" and "design" as optional and consumers expect software to be buggy.
I liked your point on DI. This is another key benefit of TDD. The number of times I had to go into someone else's code base where they just exploited singletons everywhere often makes me question my career choice.
Concise yet paints a clear picture. Kudos!
I suggest every user if you are finding this type of information so come here and visit it. Escorts in Goa