Commit 17fe94b

mo khan <mo.khan@gmail.com>
2020-11-09 05:08:56
test: use testify assertions
1 parent 71386b6
test/unit/movie_library_test.go
@@ -1,10 +1,11 @@
 package testing
 
-import "testing"
+import "github.com/stretchr/testify/assert"
 import "movies/domain"
+import "testing"
 
 func TestMovieLibrary(t *testing.T) {
-  library := domain.MovieLibrary{}
+  subject := domain.MovieLibrary{}
 
   pixar := domain.Studio{Name: "Pixar"}
   disney := domain.Studio{Name: "Disney"}
@@ -24,19 +25,19 @@ func TestMovieLibrary(t *testing.T) {
   pinocchio := domain.Movie{Title: "Pinocchio", Studio: disney, Year: 1940}
 
   t.Run("Add", func(t *testing.T) {
-    library.Add(shawshank_redemption)
-    library.Add(chasing_amy)
-    library.Add(man_on_fire)
-    library.Add(toy_story)
-    library.Add(up)
-    library.Add(cars)
-    library.Add(monsters_inc)
-    library.Add(fantasia)
-    library.Add(dumbo)
-    library.Add(pinocchio)
+    subject.Add(shawshank_redemption)
+    subject.Add(chasing_amy)
+    subject.Add(man_on_fire)
+    subject.Add(toy_story)
+    subject.Add(up)
+    subject.Add(cars)
+    subject.Add(monsters_inc)
+    subject.Add(fantasia)
+    subject.Add(dumbo)
+    subject.Add(pinocchio)
 
     t.Run("Length", func(t *testing.T) {
-      if library.Count() != 10 { t.Fatal(library.Count()) }
+      assert.Equal(t, 10, subject.Count())
     })
   })
 }
test/unit/movie_test.go
@@ -1,6 +1,7 @@
 package testing
 
 import (
+  "github.com/stretchr/testify/assert"
   "movies/domain"
   "testing"
 )
@@ -14,14 +15,14 @@ func TestMovie(t *testing.T) {
   }
 
   t.Run("Title", func(t *testing.T) {
-    if movie.Title != "A Bugs Life" { t.Fatal(movie.Title) }
+    assert.Equal(t, "A Bugs Life", movie.Title)
   })
 
   t.Run("Year", func(t *testing.T) {
-    if movie.Year != 1998 { t.Fatal(movie.Year) }
+    assert.Equal(t, 1998, movie.Year)
   })
 
   t.Run("Studio", func(t *testing.T) {
-    if movie.Studio.Name != "Pixar" { t.Fatal(movie.Studio.Name) }
+    assert.Equal(t, "Pixar", movie.Studio.Name)
   })
 }
go.mod
@@ -1,3 +1,9 @@
 module movies
 
 go 1.15
+
+require (
+	github.com/stretchr/objx v0.3.0 // indirect
+	github.com/stretchr/testify v1.6.1
+	gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
+)
go.sum
@@ -0,0 +1,18 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
+github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Makefile
@@ -1,5 +1,4 @@
-run:
-	go run main.go
+test: unit
 
 unit:
 	go test ./test/unit/...
@@ -7,6 +6,9 @@ unit:
 integration:
 	go test ./test/integration/...
 
+run:
+	go run main.go
+
 lint:
 	golint ./...