Contents

Go Tutorial Part 8 - Testing

Contents
  1. To make a test, create a new file ending in _test.go. eg deck_test
  2. to run tests go test

1 Simple Test

package main

import "testing"

func TestNewDeck(t *testing.T) {

	d := newDeck()

	if len(d) != 16 {
		t.Errorf("Expected deck length of 16 but got %v", len(d))
	}

}

Errorf is used to log errors to console

use go test to run all tests in the folder

Go does not do any cleanup after tests