Asked by:
Trying to learn unit testing, TDD and BDD

Question
-
User1140794346 posted
hi guys
I was just made redundant due to COVID, hence job hunting again in the market.
The last role I worked with MSSQL, ASP.NET Core, .net Framework and MVC (Full stack) However we never used unit testing, but had inhouse testers. So now I am trying to learn unit testing, and others like TDD, and BDD.
I am quite confused, as the examples I am seeing online, all have to do with calculations, what if my class has no calculations ???
I am looking at these and a number of videos, all seem to been around calculations
https://docs.microsoft.com/en-us/visualstudio/test/unit-test-basics?view=vs-2019
https://www.c-sharpcorner.com/article/a-basic-introduction-of-unit-test-for-beginners/
pls advice
Tuesday, October 6, 2020 7:30 PM
All replies
-
User475983607 posted
Unit testing is simply known inputs produce expected results. Typically, unit tests test business logic. The idea is rather than testing business logic while running the application, logical units are separated and test individually in a test project. Often this means rethinking how application are designed. This is where Test Driven Development (TDD) and Behavior Driven Development (BDD) come in. They provide a path for developing testable classes.
Often developers new to unit testing, create tests that include data access which is called integration testing not unit testing. Generally, the problem is understanding how to separate data access from the business logic. Unit tests typically take advantage of Interfaces, mock data, and dependency injection. This are the bit developers need to learn to get unit tests working.
Tuesday, October 6, 2020 8:27 PM -
User1120430333 posted
What is a unit test?
https://www.artima.com/weblogs/viewpost.jsp?thread=126923
Maybe you should take a better course. It doesn't cost that much for a monthly subscription. .
https://www.pluralsight.com/courses/basic-unit-testing-csharp-developers
Tuesday, October 6, 2020 9:43 PM -
User-474980206 posted
while writing units test is a skill required for TDD, it is an analysis and programing methodology. That is, TTD is a style of design and coding. It is more important to understand TDD than write a unit test. The unit test is the easy part, and one you understand the TDD methodology the unit tests come natural.
In short TDD, says to design the unit test first. this helps define the api of the class/component. You then code the component to pass the unit test.
After you master TDD, then its about code coverage with the unit tests. is there a unit test for each code branch in the component? BDD is methodology for designing good coverage in unit tests.
TDD & BDD are showing the pitfalls of object oriented design. Inheritance and internal state makes units test very complex and difficult.
you will notice that C# 9.0 is adding more support for functional programing to catch up with swift and rust
note: rust is a great language to use to learn modern TDD.
Tuesday, October 6, 2020 11:09 PM