Category Archives: Software Quality

How to use Sonar Dashboard to Report on Software Code Quality

This article represents methods one could adopt to read the sonar dashboard and gather data appropriately to monitor and control the software code quality. The primary reason why I am writing this blog is the fact that I have come across several team leads who asked me the questions related with data on sonar dashboard and what all they could do with it. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are three different aspects of software quality which could be tracked using Sonar Dashboard: Maintainability (testability, reusability & modularity) Usability (readability and understand-ability) Security Following are …

Continue reading

Posted in Software Quality. Tagged with .

Code Quality – Why Avoid Higher Cyclomatic Complexity?

This article represents my thoughts on why one should avoid a higher cyclomatic complexity (value more than 15 or so). Recently, I have been doing code reviews for multiple projects using Sonar. This is where I came across the rule called as “Cyclomatic Complexity”. The rule raises an alert for all the methods whose cyclomatic complexity is found to be more than 10. Thus, I thought of listing down reasons why one should pay attention to the cyclomatic complexity of method when he/she is writing fresh method or making changes to existing method. Personally, I do agree and strongly believe that one should avoid writing methods/function of code complexity higher than 15 or …

Continue reading

Posted in Software Quality. Tagged with .

JArchitect Version 4.0 on Mac OSX is GA for Download

Version 4.0 of JArchitect on Mac OSX is now available for anyone wishing to download and try it. JArchitect manage complex code base and achieve high Code Quality. With JArchitect, software quality can be measured using Code Metrics, visualized using Graphs and Treemaps, and enforced using standard and custom Rules via CQLinq queries. Features in JArchitect v4.0 include: A dashboard panel that shows the state of the current code base at a glance as well as a comparison to a baseline. Monitoring trends on 50 default “Trend Metrics” as well as custom trend metrics. These can be displayed through Trend Charts. Focus on recent rules violations (by using filters) that occur …

Continue reading

Posted in News, Software Quality.

How to Setup Eclipse IDE for Sonar Analysis

This article describes steps required to configure your eclipse for SonarQube such that developers are not required to leave the eclipse IDE to manage their source code quality. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are the key points described later in this article: Installing & Configuraing SonarQube in Eclipse Analyzing code using SonarQube Installing & Configuring SonarQube in Eclipse Follow the steps given on following pages to install and configure SonarQube in your Eclipse IDE. The page on Installing SonarQube in Eclipse consists of steps required to install SonarQube in the IDE. Once downloaded, it …

Continue reading

Posted in Software Engg, Software Quality. Tagged with .

How to Quickly Get Started with Sonar

get_started_with_sonar

This article represents steps required to quickly get up and running with Sonar and keep it handy for your personal Java/.NET/PHP etc related projects. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are the key points described later in this article: Sonar setup instructions Configure HelloWorld Project for Code Analysis Sonar setup instructions Following are two key aspects of getting Sonar and dependencies installed, configured and setup for usage. Installation of SonarQube Installation of Code Analyzer Installation of SonarQube Following is instruction-set to get setup with SonarQube: Go to Sonar community edition page and download. Unzip the …

Continue reading

Posted in Software Quality. Tagged with .

Top 10 PHP Code Review Tips

php_code_review_best_practices

This article represents top 10 areas to consider while you are taking up the task to do the code review of a PHP project. The other day, I had a discussion with one of the PHP senior developers who asked me about where to start on the task related with reviewing a PHP web application and, we brainstormed and came up with the list. Interestingly, apart from few, most of them can be pretty much applied to applications written with other programming languages as well. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are the key points described later …

Continue reading

Posted in PHP, Software Quality. Tagged with , .

Quick Reference to Jasmine – Javascript Unit Testing Framework

jasmine unit testing framework

The article represents the fundamentals concepts and code samples around Jasmine, a popular Javascript unit testing framework.TO get started, download the framework from https://github.com/pivotal/jasmine/releases. For detailed examples, look at http://jasmine.github.io/edge/introduction.html. It All Starts with “describe” and “it” Function Blocks In Jasmine terminologies, a set of tests is collectively called as a “suite”. The test suite is defined using “describe” function block. Each test is called as a “spec” and defined using “it” function block. A test suite can have multiple test specs and also, test suites. This implies that a “describe” function block can have multiple “it” function blocks and also, “describe” function blocks contained within. One of the key …

Continue reading

Posted in Testing, Tools, UI, Unit Testing. Tagged with , .

Unit Testing with JUnit & Mockito – Code Examples

unit testing

The article presents quick code example for doing unit testing with JUnit & Mockito mocking framework. It also represents unit testing naming convention where features text is used for naming the test methods thereby representing test class as alternate documentation for the class under test. Following is done while defining Mock member variables Use @Mock annotation ahead of member variable definitions Following are steps done in the setup method: Initialize the mock using MockitoAnnotations.initMocks(this); Object of class under test is initialized with the mock objects Following steps are used in each of the unit test methods: Create/Initialize required objects for working with mocks and methods under test Set the mock …

Continue reading

Posted in Unit Testing. Tagged with , .

7 Popular Unit Test Naming Conventions

unit-testing

The article presents a compiled list of unit tests naming strategy that one could follow for naming their unit tests. The article is intended to be a quick reference instead of going through multiple great pages such as following. That said, to know greater details, please feel free access one of these pages listed below and know for yourself. Naming Standards for Unit Tests Naming Unit Tests Responsibly What are some popular naming conventions for unit tests? Unit Tests Naming Best Practices GivenWhenThen Technique Following are 7 popular unit tests naming conventions that are found to be used by majority of developers and compiled from above pages: MethodName_StateUnderTest_ExpectedBehavior: There are …

Continue reading

Posted in Unit Testing. Tagged with .

AngularJS – 7 Steps for Unit Testing AngularJS Scripts with Jasmine

This article presents instructions on what would it take to create a setup and run unit testing for your AngularJS scripts using Jasmine framework. I shall be presenting various samples on my AngularJS website, http://hello-angularjs.appspot.com. Sorry for the typos in this article and please feel free to suggest/add any points if I missed them out.   Following are key steps:  Learn Jasmine Create Unit Tests using Jasmine Download and install NodeJS Download & Install Karma Configure Karma Place Scripts Appropriately Execute Tests   Learn Jasmine Jasmine, one of the very popular Javascript unit testing framework, can be used for unit testing one’s AngularJS scripts. As a matter of fact, Angular …

Continue reading

Posted in Javascript, UI, Unit Testing. Tagged with , , .

Java Unit Testing Interview Questions

ATG interview questions

The article presents some of the frequently asked interview questions in relation with unit testing with Java code. Please suggest other questions tthat you came across and I shall include in the list below. What is unit testing? Which unit testing framework did you use? What are some of the common Java unit testing frameworks? Ans: Read the definition of Unit testing on Wikipedia page for unit testing. Simply speaking, unit testing is about testing a block of code in isolation. There are two popular unit testing framework in Java named as Junit, TestNG.   In SDLC, When is the right time to start writing unit tests? Ans: Test-along if …

Continue reading

Posted in Interview questions, Unit Testing. Tagged with , , .

Test-Driven Development (TDD) Shines with Mocking

The article presents a perspective and some code samples on how one could some cool stuff with Test-driven development (TDD) and Mocking. The code samples are done in Java. Lets briefly understand what is TDD and mocking? What is TDD? Test-driven development, simply speaking, is a software development process in which developers write tests first and, then writing enough code to pass those tests. Once all of the tests pass, they do code refactoring to enhance code quality. Following are key advantages of adopting TDD as your development process: Enforces the developers to thoroughly think through various different test cases which could be used to test the functional/business requirements. It, …

Continue reading

Posted in Unit Testing. Tagged with , .

Law of Demeter Coding Violations & How to Fix Them

The article lists down Law of Demeter Violations and presents solutions on how to fix them. The code samples are written in Java. Feel free to share your comment, if any. What is Law of Demeter Principle? There are several good pages on the web which could be read to understand the object-oriented principle, Law of Demeter. Following are some of them: Demeter: It’s not just a good idea. It’s the law. Object-Oriented Programming: An Objective Sense of Style PMB Coding Violations The group of programmers working on a Demeter system, back in 1980, came up with this programming principle which they termed as Law of Demeter. According to them, …

Continue reading

Posted in Software Quality. Tagged with , .

Unit Tests – Mocking vs Stubbing Vs Spying

The article lists down some good reads (from different webpages on internet) on unit testing concepts such as mocking, stubbing and spying and represents summarized information on these concepts. Mocks Aren’t Stubs What’s the difference between a mock & stub? Mocking vs. Spying in mocking frameworks Mocking and stubbing in Ruby on Rails What’s the difference between faking, mocking, and stubbing? After going through all the above pages, I could arrive at following definitions: Mocking Mocking is a unit testing phenomenon which is used to replace real objects with test objects that mocks the behavior. These test objects are called as Mock objects. The point to note is that mock …

Continue reading

Posted in Unit Testing. Tagged with .

Top 5 Unit Testing Best Practices

The article lists down top 5 unit testing best practices that one could adopt to be able to write great unit tests with greater code coverage. Test-Along, if not Test-Driven Many a times, rookies have been found to start writing unit tests once they have written most of the code, e.g., towards the end of the coding. However, to make the most of unit tests, one should write them as they write the code. This is somewhat different and less difficult than writing tests first and code later as in test-driven development (TDD). Following are some of the advantages of doing “test-along” development: One could achieve greater code coverage by …

Continue reading

Posted in Unit Testing. Tagged with .

Junit & Mock Framework Mockito Code Samples – Part 1

The article represents code samples for Junit tests and Mockito, a mocking framework. In addition, it describes different aspects of unit testing and mocking. Software Requirement The goal is to create a simple piece of software which caters to the requirement of school admission where in applicants submit their admission application.   Class Design & JUnit Tests To meet above requirement, following different component is designed: Core Components (Key Ones) AdmissionApplication.java: Consists of method recordNewApplication which validates the submitted application, and later, stores in the database after successful validation. ApplicationValidation.java: Consists of methods for validating business rules associated with admission such as mandatory inputs (first name, last name, class, gender, …

Continue reading

Posted in Unit Testing. Tagged with , .