Golang testing.InternalExample type and RunExamples() function example
package testing
Golang testing.InternalExample type and RunExamples() function usage example
package main
import (
//"errors"
"fmt"
"strings"
"testing"
)
func compareString(string1 string, string2 string) (bool, error) {
err := error(nil)
//if len(string1) <= 0 || len(string2) <= 0 {
// err = errors.New("String cannot be empty")
//}
ok := strings.EqualFold(string2, string1)
return ok, err
}
func main() {
// http://golang.org/pkg/testing/#InternalExample
firstExample := testing.InternalExample{Name: "Example", F: func() {}, Output: ""}
secondExample := testing.InternalExample{Name: "Example", F: func() {}, Output: ""}
Examples := make([]testing.InternalExample, 2)
Examples[0] = firstExample
Examples[1] = secondExample
// feed all tests examples against
complete := testing.RunExamples(compareString, Examples)
fmt.Printf("All test examples completed? : %v\n", complete)
}
References :
Advertisement
Something interesting
Tutorials
+19.2k Golang : Populate dropdown with html/template example
+8.3k Swift : Convert (cast) Character to Integer?
+87.7k Golang : How to convert character to ASCII and back
+16.9k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+29.1k Golang : Get first few and last few characters from string
+6k Golang : How to verify input is rune?
+9.1k Golang : Handle sub domain with Gin
+19.3k Golang : Get RGBA values of each image pixel
+12k Golang : Find and draw contours with OpenCV example
+10.1k Golang : Identifying Golang HTTP client request
+8.1k Golang : HTTP Server Example
+19.9k Golang : How to get time from unix nano example