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

Unit Testing: Indispensable

DZone's Guide to

Unit Testing: Indispensable

Skipping unit testing can be dangerous. See why and learn how to start integrating it into your DevOps development process.

· DevOps Zone ·
Free Resource

Monitor your CI/CD pipelines end-to-end with Hygieia, an open source dashboard from Capital One.

What Is Unit Testing?

Testing the lowest possible units, i.e. functions or methods. Functions/methods can be further decomposes into statements, conditions, and expressions. Testing functions or methods eventually tests these individual statements, conditions, and expressions.

Unit Testing is possibly the lowest level of testing in a software product lifecycle. It is an inevitable activity in software development but the answer to this genuine question of whether developers and programmers effectively perform unit testing will honestly be NO due to:

  1. Immature knowledge on Unit Testing skills.

  2. Negligence; yes, they know but are too lazy or overconfident.

  3. Don’t have time; maybe efforts burned up due to various reasons so they are delivering the product by compromising Unit Testing.

The first point is about skill development, which can be easily achieved, and the third point is a process issue, which can also be easily overcome. But the second is about attitude and mindset, which are very had to change.

Ignoring Unit Testing Is a Disaster

Yes, a developer should not ignore unit testing at any cost and in any situation, because we are here to deliver a quality product to our stakeholders and it’s a great commitment.

Imagine if software has more defects in production; it will not leave our stakeholders happy if their business is impacted, which create frustration, and eventually, the relationship is not going to last forever.

If we spend our effort and time on fixing the defects and bugs, then we are not going to create any value for our stakeholders and there will be no room for innovation at all.

Even developers are also brand representatives, so poor code leads to reputational damage to our organization.

So, What Can Be Done?

Collaboration:

  • It’s the key to avoiding most of the problems which also works well here: collaborate with key stakeholders.

  • With BA to understand the requirement well and clearly.

  • With System Testers to make sure all our understanding is correct, as well as the possible positive scenarios and negative scenarios applicable.

  • With peers, which is also very important in order to get a third eye view.

Process: 

  • Choosing a Unit Testing approach: manual or automation, not combined.

  • Implement a test-driven BDD or TDD approach in the software development phase.

  • Have a code coverage threshold value and strictly adhere to it.

  • Add a mandatory code review criterion to review the UT test cases strictly.

  • Leads need to review code coverage reports on a periodic basis.

  • Identify the testing skills gap in the team and rectify it if any.

Skill Set:

Developing skill sets which compliment Unit Testing will lead to writing effective Unit Testing cases:

  • Once we get an idea of basic testing techniques, then it’s time to learn the language-specific testing frameworks like JUnit, NUnits , PHP Unit, etc.

  • InBuilt testing related feature in the IDEs.

  • Mocking frameworks (Mockito, EasyMock): Unit Testing always requires mocking as the external dependencies may not be fully functional or unavailable at the time, so one needs to spend considerable time in learning this mocking framework.

So on a concluding note: embrace Unit Testing completely and produce quality software products with low costs. Better late than never.

Track and monitor your entire CI/CD pipeline on a single pane of glass. Hygieia is an open source, visual dashboard for keeping CI/CD pipelines green.

Topics:
unit testing ,software testing ,devops

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}