当前位置: 首页>>代码示例>>Golang>>正文


Golang T.Run方法代码示例

本文整理汇总了Golang中testing.T.Run方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Run方法的具体用法?Golang T.Run怎么用?Golang T.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.T的用法示例。


在下文中一共展示了T.Run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestFalse

func TestFalse(t *testing.T) {
	t.Run("should not end testing if the condition is falsey", func(t *testing.T) {
		tester := new(mockTester)

		assert.False(tester, false, "")

		if tester.errorfCalls != 0 {
			t.Errorf(
				"Expected Errorf not to have been called, it had been called %d times.",
				tester.errorfCalls,
			)
		}
	})

	t.Run("should end testing if the condition is truthy", func(t *testing.T) {
		tester := new(mockTester)

		assert.False(tester, true, "")

		if tester.errorfCalls != 1 {
			t.Errorf(
				"Expected Errorf to have been called once, it had been called %d times.",
				tester.errorfCalls,
			)
		}
	})
}
开发者ID:eidolon,项目名称:console,代码行数:27,代码来源:assert_test.go

示例2: TestExamples

func TestExamples(t *testing.T) {
	flag.Parse()
	if !*examplesTest && os.Getenv("CI") == "" {
		t.Skip("skipping examples tests, pass --examples to execute it")
		return
	}

	defer deleteTempFolders()

	examples, err := filepath.Glob(examplesFolder())
	if err != nil {
		t.Errorf("error finding tests: %s", err)
	}

	for _, example := range examples {
		_, name := filepath.Split(filepath.Dir(example))

		if ignored[name] {
			continue
		}

		t.Run(name, func(t *testing.T) {
			testExample(t, name, example)
		})
	}
}
开发者ID:src-d,项目名称:go-git,代码行数:26,代码来源:common_test.go

示例3: TestParseHexColor

func TestParseHexColor(t *testing.T) {
	for _, tc := range []struct {
		hex      string
		expected color.Color
	}{
		{
			hex:      "F84",
			expected: color.NRGBA{R: 0xff, G: 0x88, B: 0x44, A: 0xff},
		},
		{
			hex:      "F842",
			expected: color.NRGBA{R: 0x88, G: 0x44, B: 0x22, A: 0xff},
		},
		{
			hex:      "FC8642",
			expected: color.NRGBA{R: 0xfc, G: 0x86, B: 0x42, A: 0xff},
		},
		{
			hex:      "FC864210",
			expected: color.NRGBA{R: 0x86, G: 0x42, B: 0x10, A: 0xfc},
		},
	} {
		t.Run(tc.hex, func(t *testing.T) {
			res, err := parseHexColor(tc.hex)
			if err != nil {
				t.Fatal(err)
			}
			if res != tc.expected {
				t.Fatalf("unexpected result for \"%s\": got %#v, want %#v", tc.hex, res, tc.expected)
			}
		})
	}
}
开发者ID:pierrre,项目名称:imageserver,代码行数:33,代码来源:rotate_test.go

示例4: TestScanln

func TestScanln(t *testing.T) {
	for _, r := range readers {
		t.Run(r.name, func(t *testing.T) {
			testScan(t, r.f, Fscanln)
		})
	}
}
开发者ID:achanda,项目名称:go,代码行数:7,代码来源:scan_test.go

示例5: TestHandlerAdd

func TestHandlerAdd(t *testing.T) {
	tests := []struct {
		description string
		params      *articles.HandlerAddParams
		code        int
	}{
		{"No Title", &articles.HandlerAddParams{}, http.StatusBadRequest},
		{"Title filled with spaces", &articles.HandlerAddParams{Title: "       "}, http.StatusBadRequest},
		{"As few params as possible", &articles.HandlerAddParams{Title: "My Super Article"}, http.StatusCreated},
		{"Duplicate title", &articles.HandlerAddParams{Title: "My Super Article"}, http.StatusCreated},
	}

	for _, tc := range tests {
		t.Run(tc.description, func(t *testing.T) {
			rec := callHandlerAdd(t, tc.params)
			assert.Equal(t, tc.code, rec.Code)

			if rec.Code == http.StatusCreated {
				var a articles.Article
				if err := json.NewDecoder(rec.Body).Decode(&a); err != nil {
					t.Fatal(err)
				}

				assert.NotEmpty(t, a.ID)
				assert.NotEmpty(t, a.Slug)
				assert.Equal(t, tc.params.Title, a.Title)
				if err := a.FullyDelete(); err != nil {
					t.Fatal(err)
				}
			}
		})
	}
}
开发者ID:Nivl,项目名称:api.melvin.la,代码行数:33,代码来源:handler_add_test.go

示例6: TestRefreshAsync

func TestRefreshAsync(t *testing.T) {
	t.Parallel()

	for _, scenario := range refreshAsyncScenarios {
		t.Run(scenario.description, func(t *testing.T) {
			discovery := dnsdisco.NewDiscovery(scenario.service, scenario.proto, scenario.name)
			discovery.SetRetriever(scenario.retriever)
			discovery.SetHealthChecker(scenario.healthChecker)

			finish := discovery.RefreshAsync(scenario.refreshInterval)
			defer close(finish)

			time.Sleep(scenario.refreshInterval + (50 * time.Millisecond))
			target, port := discovery.Choose()

			if target != scenario.expectedTarget {
				t.Errorf("mismatch targets. Expecting: “%s”; found “%s”", scenario.expectedTarget, target)
			}

			if port != scenario.expectedPort {
				t.Errorf("mismatch ports. Expecting: “%d”; found “%d”", scenario.expectedPort, port)
			}

			if errs := discovery.Errors(); !reflect.DeepEqual(errs, scenario.expectedErrors) {
				t.Errorf("mismatch errors. Expecting: “%#v”; found “%#v”", scenario.expectedErrors, errs)
			}
		})
	}
}
开发者ID:rafaeljusto,项目名称:dnsdisco,代码行数:29,代码来源:dnsdisco_test.go

示例7: TestReplace

func TestReplace(t *testing.T) {
	tests := []struct {
		where  string
		start  int
		end    int
		what   string
		result string
	}{
		{"0123456789", 3, 5, "abcdef", "012abcdef56789"},
		{"0123456789", 3, 5, "ab", "012ab56789"},
		{"0123456789", 3, 3, "abcd", "012abcd3456789"},
		{"0123456789", 0, 2, "abcd", "abcd23456789"},
		{"0123456789", 0, 0, "ab", "ab0123456789"},
		{"0123456789", 10, 10, "ab", "0123456789ab"},
		{"0123456789", 8, 10, "ab", "01234567ab"},
		{"0123456789", 5, 5, "", "0123456789"},
		{"0123456789", 3, 8, "", "01289"},
		{"0123456789", 3, 8, "ab", "012ab89"},
		{"0123456789", 0, 5, "a", "a56789"},
		{"0123456789", 5, 10, "ab", "01234ab"},
	}
	for _, test := range tests {
		t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
			result := replace([]byte(test.where), test.start, test.end, []byte(test.what))
			if test.result != string(result) {
				t.Errorf("want '%v', got '%v'", test.result, string(result))
			}
		})
	}
}
开发者ID:sploving,项目名称:syzkaller,代码行数:30,代码来源:report_test.go

示例8: TestDeterministic

// Test if two runs produce identical results
// even when writing different sizes to the Writer.
func TestDeterministic(t *testing.T) {
	t.Parallel()
	for i := 0; i <= 9; i++ {
		t.Run(fmt.Sprint("L", i), func(t *testing.T) { testDeterministic(i, t) })
	}
	t.Run("LM2", func(t *testing.T) { testDeterministic(-2, t) })
}
开发者ID:Harvey-OS,项目名称:go,代码行数:9,代码来源:writer_test.go

示例9: TestDiff_DeepCopy

func TestDiff_DeepCopy(t *testing.T) {
	cases := map[string]*Diff{
		"empty": &Diff{},

		"basic diff": &Diff{
			Modules: []*ModuleDiff{
				&ModuleDiff{
					Path: []string{"root"},
					Resources: map[string]*InstanceDiff{
						"aws_instance.foo": &InstanceDiff{
							Attributes: map[string]*ResourceAttrDiff{
								"num": &ResourceAttrDiff{
									Old: "0",
									New: "2",
								},
							},
						},
					},
				},
			},
		},
	}

	for name, tc := range cases {
		t.Run(name, func(t *testing.T) {
			dup := tc.DeepCopy()
			if !reflect.DeepEqual(dup, tc) {
				t.Fatalf("\n%#v\n\n%#v", dup, tc)
			}
		})
	}
}
开发者ID:mhlias,项目名称:terraform,代码行数:32,代码来源:diff_test.go

示例10: TestStateDeepCopy

func TestStateDeepCopy(t *testing.T) {
	cases := []struct {
		One, Two *State
		F        func(*State) interface{}
	}{
		// Version
		{
			&State{Version: 5},
			&State{Version: 5},
			func(s *State) interface{} { return s.Version },
		},

		// TFVersion
		{
			&State{TFVersion: "5"},
			&State{TFVersion: "5"},
			func(s *State) interface{} { return s.TFVersion },
		},
	}

	for i, tc := range cases {
		t.Run(fmt.Sprintf("copy-%d", i), func(t *testing.T) {
			actual := tc.F(tc.One.DeepCopy())
			expected := tc.F(tc.Two)
			if !reflect.DeepEqual(actual, expected) {
				t.Fatalf("Bad: %d\n\n%s\n\n%s", i, actual, expected)
			}
		})
	}
}
开发者ID:BSick7,项目名称:terraform,代码行数:30,代码来源:state_test.go

示例11: testOrm

func testOrm(t *testing.T, o *Orm, name string) {
	tests := []func(*testing.T, *Orm){
		testCodecs,
		testAutoIncrement,
		testTime,
		testSaveDelete,
		testLoadSaveMethods,
		testLoadSaveMethodsErrors,
		testData,
		testInnerPointer,
		testTransactions,
		testFuncTransactions,
		testCompositePrimaryKey,
		testReferences,
		testQueryAll,
		testDefaults,
		testMigrations,
		testSaveUnchanged,
		testQueryTransform,
	}
	for _, v := range tests {
		t.Run(testName(name, v), func(t *testing.T) {
			clearRegistry(o)
			v(t, o)
		})
	}
}
开发者ID:rainycape,项目名称:gondola,代码行数:27,代码来源:orm_impl_test.go

示例12: TestGenerator

func TestGenerator(t *testing.T) {
	for _, s := range []string{"gen_anyof_good_bad"} {
		t.Run(s, func(t *testing.T) {
			testHelper(t, "data/"+s)
		})
	}
}
开发者ID:dgraph-io,项目名称:benchmarks,代码行数:7,代码来源:index_test.go

示例13: TestEqual

func TestEqual(t *testing.T) {
	t.Run("should not end testing if the expected equals the actual", func(t *testing.T) {
		tester := new(mockTester)

		assert.Equal(tester, 42, 42)

		if tester.errorfCalls != 0 {
			t.Errorf(
				"Expected Errorf not to have been called, it had been called %d times.",
				tester.errorfCalls,
			)
		}
	})

	t.Run("should end testing if the expected does not equal the actual", func(t *testing.T) {
		tester := new(mockTester)

		assert.Equal(tester, 24, 42)

		if tester.errorfCalls != 1 {
			t.Errorf(
				"Expected Errorf to have been called once, it had been called %d times.",
				tester.errorfCalls,
			)
		}
	})
}
开发者ID:eidolon,项目名称:console,代码行数:27,代码来源:assert_test.go

示例14: TestParseSysRCOutput

func TestParseSysRCOutput(t *testing.T) {
	table := []struct {
		Input string
		K     string
		V     string
	}{
		{
			Input: "keyrate: fast\n",
			K:     "keyrate",
			V:     "fast",
		},
		{
			Input: "dumpdev: \n",
			K:     "dumpdev",
			V:     "",
		},
	}

	for _, item := range table {
		t.Run(item.Input, func(t *testing.T) {
			k, v, err := parseSysRCOutput(item.Input)
			if err != nil {
				t.Error(err)
			}
			if k != item.K || v != item.V {
				t.Errorf("expected: k=%q, v=%q, got: k=%q, v=%q", item.K, item.V, k, v)
			}
		})
	}
}
开发者ID:dnaeon,项目名称:gru,代码行数:30,代码来源:sysrc_freebsd_test.go

示例15: TestMedia

func TestMedia(t *testing.T) {
	cases := []struct {
		input    []int64
		expected []int64
	}{
		{
			[]int64{1, 2, 3, 4, 5, 6},
			[]int64{1, 1, 2, 2, 3, 3},
		},
		{
			[]int64{10, 30, 20, 31, 32, 33, 40, 1, 2},
			[]int64{10, 10, 20, 20, 30, 30, 31, 30, 30},
		},
	}

	for i, tc := range cases {
		t.Run(strconv.Itoa(i), func(t *testing.T) {
			m := &Median{}
			for i, n := range tc.input {
				m.Add(n)
				t.Logf("Added %d Median: %d Struct: %v", n, m.Value(), m)
				if m.Value() != tc.expected[i] {
					t.Errorf("got median %d wanted %d", m.Value(), tc.expected[i])
				}
			}
		})
	}
}
开发者ID:nveeser,项目名称:peyta.com,代码行数:28,代码来源:median_test.go


注:本文中的testing.T.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。