Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Testing right by testing the right thing

DZone's Guide to

Testing right by testing the right thing

· DevOps Zone ·
Free Resource

Automatic continuous monitoring keeps continuous deployment pipelines flowing smoothly and efficiently. Try Instana APM to automatically monitor containers and microservices!

Before answering questions about unit testing I usually tend to ask some questions to get the broader picture – especially if the question sound sstrange.

Such a question was asked by a teammate – he wanted to know if he could replace the behavior of a fake object while still calling the method replaced. This sounded a bit strange to me – either you want to fake an object or you don’t, so I asked him if he happens to test the functionality of the same object he’s faking – he answered 'no' but he needs the method to run in order for the test to pass.

At first he insisted that he wants to test if a problem report in the system was closed twice, so he needs to count the times that the close method was called while still calling it. Next I asked him 'how does the user notice the issue, does our user care that he closes the report twice?' obviously the user does not care. After further inquiry I manage to find that if a close operation is performed on an already close report an exception is thrown and the user does not get notification for the end of the running process. After we came to that conclusion he managed to write a simple unit test that checks whether the user is notified in no time.

In retrospect I could have told him how to solve the issue he had using our Isolation framework of choice – the result would have a been a poorly written, fragile test.

Fragile Box by DHDesign, on Flickr
Creative Commons Attribution-Noncommercial 2.0 Generic License  by DHDesign

 

Happy coding…

Automatic real-time observability is critical to getting the full benefit of CI/CD. Hear @DevOpsDon discuss how Franklin American Mortgage Company cut their new application deployment time from 6-12 months to 2 weeks with the help of Instana APM.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}