How to write unit tests

Create a _test.go file with Test functions and run go test to verify your code logic.

Write unit tests by creating a file named package_test.go in your package directory, importing testing, and defining functions that start with Test followed by a capital letter.

package yourpackage

import "testing"

func TestYourFunction(t *testing.T) {
	// Arrange
	input := 5
	// Act
	result := YourFunction(input)
	// Assert
	if result != 10 {
		t.Errorf("Expected 10, got %d", result)
	}
}

Run the tests with go test ./....