What is a unit in unit testing? Is it a class, a function, a method, all of the above?
Is it considered a unit test if we are testing a class without mocking all of the collaborators?
What is a unit in unit testing? Is it a class, a function, a method, all of the above?
Is it considered a unit test if we are testing a class without mocking all of the collaborators?
For further actions, you may consider blocking this person and/or reporting abuse
Necati Γzmen -
Kailash P. -
Manuel Rivero -
Guillaume Duhan -
Once suspended, s_anastasov will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, s_anastasov will be able to comment and publish posts again.
Once unpublished, all posts by s_anastasov will become hidden and only accessible to themselves.
If s_anastasov is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Stojan Anastasov.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community π©βπ»π¨βπ» safe. Here is what you can do to flag s_anastasov:
Unflagging s_anastasov will restore default visibility to their posts.
Top comments (5)
I agree on point 1.
Can you elaborate on point 2?
You must isolate dependencies.
When test failed, where is the error? This is in the unit or in the dependency? When you use a mock, you will know where it is.
You may use more mocks for more test scenarios too.
I like to think of "units" as lego bricks. We like to create useful lego bricks that we can stick together to create systems.
These lego bricks could be a single class/function with a few lines of code but it might have a bunch of private stuff inside and maybe creates instances of other classes to do its job.
Unit test the boundaries of your lego bricks.
For me the acid test with unit tests is i ask myself if something is clearly implementation detail. If it is, you're testing too low level, move up the abstraction tree a bit.
If you're testing something that expresses an important business rule, that's probably a good unit test.
In respect to TDD a lot of people make a mistake in thinking that you must write a new test for each new class/function you write. That was never the intention. You write a new test for each new captured behaviour. If you stick to this rule your unit tests will document and verify real things... or units (e.g when I deposit Β£10 into an empty account the balance should be Β£10)
I speak about this here youtube.com/watch?v=Kwtit8ZEK7U (or you can read here quii.dev/The_Tests_Talk)
I think it's all. The unit is possible to be a function, a class or a method.