mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-07-20 15:12:52 +02:00
initial import
This commit is contained in:
12
quality/unittest/cmd/main.go
Normal file
12
quality/unittest/cmd/main.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.source-fellows.com/samples/unittest/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
res := math.Add(1, 2)
|
||||
fmt.Printf("Das Ergbnis ist %v", res)
|
||||
}
|
3
quality/unittest/go.mod
Normal file
3
quality/unittest/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module golang.source-fellows.com/samples/unittest
|
||||
|
||||
go 1.13
|
6
quality/unittest/math/add.go
Normal file
6
quality/unittest/math/add.go
Normal file
@ -0,0 +1,6 @@
|
||||
package math
|
||||
|
||||
// Add adds two integer values.
|
||||
func Add(a int, b int) int {
|
||||
return a + b
|
||||
}
|
42
quality/unittest/math/add_test.go
Normal file
42
quality/unittest/math/add_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package math_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.source-fellows.com/samples/unittest/math"
|
||||
)
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
res := math.Add(1, 2)
|
||||
if res != 3 {
|
||||
t.Fatalf("Not the expected result %v", res)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var testdata = []struct {
|
||||
name string
|
||||
param1 int
|
||||
param2 int
|
||||
result int
|
||||
}{
|
||||
{"positiv1", 1, 2, 3},
|
||||
{"positiv2", 2, 3, 5},
|
||||
{"negativ1", -2, 3, 5}, //stimmt nicht! - zur Demo von Testfehlern
|
||||
{"negativ2", 2, -3, 7}, //stimmt nicht! - zur Demo von Testfehlern
|
||||
}
|
||||
|
||||
func TestTableAdd(t *testing.T) {
|
||||
for _, tt := range testdata {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt := tt
|
||||
t.Parallel()
|
||||
result := math.Add(tt.param1, tt.param2)
|
||||
time.Sleep(time.Second * 1)
|
||||
if result != tt.result {
|
||||
t.Errorf("%v not expected. Expected: %v", result, tt.result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user