Posts

Showing posts from February, 2021

Java Coding Guidelines and JUnit Rules

Coding Guidelines Table of Contents Coding Guidelines RULE-1 : Log Before throwing Exception RULE-2 : Avoid else cases if possible RULE-3 : Don’t write big conditional blocks RULE-4 : Don’t return null Collection Type from method RULE-4 : Define constants in Utility class, not in interface RULE-5 : Always Use Runtime exceptions JUnit Testing Rules UnitTest with ExpectedException Rule UnitTest with assertThrows (Java8 Lambda) UnitTest with System.exit() Rule UnitTest with Timeout Rule UnitTest with TemporaryFolder Rule Plugins Save action plugin SonarLint plugin Coding Guidelines Following coding guide lines are very simple rules but it has big impact on code quality, readability, indentation and test coverage. Improves readability of the code with proper indentation Helps to write Test compatible code (You can write better positive/negative tests) Helps to write more optimized code Note java doesn’t care ab