[go] testing/synctest: add Subtest

0 views
Skip to first unread message

qiu laidongfeng (Gerrit)

unread,
Jun 6, 2026, 11:54:11 PM (2 hours ago) Jun 6
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

qiu laidongfeng has uploaded the change for review

Commit message

testing/synctest: add Subtest

Fixes #77320
Change-Id: I1ca7480dceb0a95d223ae1618c0e9dd23abe5d49

Change diff

diff --git a/api/next/77320.txt b/api/next/77320.txt
new file mode 100644
index 0000000..df007f9
--- /dev/null
+++ b/api/next/77320.txt
@@ -0,0 +1 @@
+pkg testing/synctest, func Subtest(*testing.T, string, func(*testing.T)) #77320
diff --git a/doc/next/6-stdlib/99-minor/testing/synctest/77320.md b/doc/next/6-stdlib/99-minor/testing/synctest/77320.md
new file mode 100644
index 0000000..53b3639
--- /dev/null
+++ b/doc/next/6-stdlib/99-minor/testing/synctest/77320.md
@@ -0,0 +1 @@
+The new [Subtest] helper function combines [testing.(*T).Run] and [testing/synctest.Test].
diff --git a/src/testing/synctest/synctest.go b/src/testing/synctest/synctest.go
index f254d56..7827849 100644
--- a/src/testing/synctest/synctest.go
+++ b/src/testing/synctest/synctest.go
@@ -330,3 +330,14 @@
time.Sleep(d)
Wait()
}
+
+// Subtest runs f in a bubble as a subtest of t called name.
+//
+// It is exactly equivalent to calling t.Run with a function that calls [Test].
+func Subtest(t *testing.T, name string, f func(*testing.T)) {
+ t.Helper()
+ t.Run(name, func(t *testing.T) {
+ t.Helper()
+ Test(t, f)
+ })
+}

Change information

Files:
  • A api/next/77320.txt
  • A doc/next/6-stdlib/99-minor/testing/synctest/77320.md
  • M src/testing/synctest/synctest.go
Change size: S
Delta: 3 files changed, 13 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I1ca7480dceb0a95d223ae1618c0e9dd23abe5d49
Gerrit-Change-Number: 787940
Gerrit-PatchSet: 1
Gerrit-Owner: qiu laidongfeng <26454...@qq.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

qiu laidongfeng (Gerrit)

unread,
Jun 6, 2026, 11:56:00 PM (2 hours ago) Jun 6
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

qiu laidongfeng voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I1ca7480dceb0a95d223ae1618c0e9dd23abe5d49
Gerrit-Change-Number: 787940
Gerrit-PatchSet: 1
Gerrit-Owner: qiu laidongfeng <26454...@qq.com>
Gerrit-Reviewer: qiu laidongfeng <26454...@qq.com>
Gerrit-Comment-Date: Sun, 07 Jun 2026 03:55:51 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages