From 35426ed5dc5196374332498c82b4d480b05e5ac5 Mon Sep 17 00:00:00 2001 From: Veniamin Albaev Date: Thu, 27 Dec 2018 13:51:44 +0300 Subject: Tests refactoring Primary motivation: Avoid statefull tests with not ignorable git file tree changes. Multiple tests reads and overwrites signle file for won needs. Multiple tests reads and overwrites file under version control. Secondary motivation: Minimal tests logic aligment, separate error expectation and not error expectation tests. Introduce sub-test over test data sets and so far. This commit is not ideal but necessary (IMHO) --- date_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'date_test.go') diff --git a/date_test.go b/date_test.go index 06421b8..a1bfbf4 100644 --- a/date_test.go +++ b/date_test.go @@ -1,8 +1,11 @@ package excelize import ( + "fmt" "testing" "time" + + "github.com/stretchr/testify/assert" ) type dateTest struct { @@ -18,10 +21,10 @@ func TestTimeToExcelTime(t *testing.T) { {401769.0, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)}, } - for _, test := range trueExpectedInputList { - if test.ExcelValue != timeToExcelTime(test.GoValue) { - t.Fatalf("Expected %v from %v = true, got %v\n", test.ExcelValue, test.GoValue, timeToExcelTime(test.GoValue)) - } + for i, test := range trueExpectedInputList { + t.Run(fmt.Sprintf("TestData%d", i+1), func(t *testing.T) { + assert.Equal(t, test.ExcelValue, timeToExcelTime(test.GoValue)) + }) } } @@ -34,9 +37,9 @@ func TestTimeFromExcelTime(t *testing.T) { {401769.0, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)}, } - for _, test := range trueExpectedInputList { - if test.GoValue != timeFromExcelTime(test.ExcelValue, false) { - t.Fatalf("Expected %v from %v = true, got %v\n", test.GoValue, test.ExcelValue, timeFromExcelTime(test.ExcelValue, false)) - } + for i, test := range trueExpectedInputList { + t.Run(fmt.Sprintf("TestData%d", i+1), func(t *testing.T) { + assert.Equal(t, test.GoValue, timeFromExcelTime(test.ExcelValue, false)) + }) } } -- cgit v1.2.1