DEV Community

Discussion on: How do you like to unit test your code?

Collapse
 
sebastientorres profile image
sebastientorres

It depends...
It depends on whether it's a single class \ method that does a single thing, such as calculations or validations, or you need to validate a process \ workflow.

I think integration testing is to validate that the overall behaviour of an aspect of your code works as you think it should; thus an integration of classes, packages and libraries.

I think it's better to use as much real code as possible and rely as little as possible on mocks.

Collapse
 
joshualjohnson profile image
Joshua Johnson

Love your explanation. I feel the same way about testing. I much rather prefer not to mock at all. Unless you rely on an environmental dependency that HAS to be mocked.

Collapse
 
sebastientorres profile image
sebastientorres

Thanks!
Mocking stuff can be a real pain and takes a lot of time to work out if everything needed for the test is available (mocked).

Thread Thread
 
joshualjohnson profile image
Joshua Johnson

Lol! Takes more work sometimes to do that than to just run it fully integrated.