Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 17. Debugging Go > Building Unit Tests

Building Unit Tests

From: eg/eg_test.go

 1  package eg
 2  import "testing"
 3
 4  func TestExample(t *testing.T) {
 5    e := NewExample()
 6      // Don't do this!
 7    _ = e.(*concreteType)
 8    if e.Name() != "Concrete type" {
 9      t.Fail()
10    }
11    t.Errorf("This test is buggy")
12  }


Go includes a simple but powerful unit test framework. The eg_test.go file shows a simple set of unit tests for the package in the last chapter.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial