Sign in

Gopher

Hi everyone, in this hands on blog i would like to demonstrate simple unit testing in Golang which will help you get started. Let’s take simple go file (main.go) where there is an interface and a concrete implementation that we will test in this blog lab.

Simple Interest Calculator

Let’s examine the contents of the file.

  • LoanInfo struct which is a simple model with one field interestInPercent . As the name suggests, its a model representing information about a Loan.
  • NewLoanInfo LoanInfo constructor function with basic validation.
  • Calculator interface which has one abstract method SimpleInterest , takes principal amount (USD)…

Abhishek

Software Engineer | Foodie | Travel Enthusiast | Drone hobbyist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store