Skip to content

proposal: testing: add Test function #32067

Description

@rogpeppe

The testing package has long contained the Benchmark function, which allows code in a non-testing source file to run benchmarks.

It is sometimes useful to be able to run test code in a non-testing context too; for example to demonstrate a failing test in the Go playground.

Perhaps something like this?

// Test runs f as a test with the given name. Any test output
// is written to w. Test reports whether the test has succeeded.
func Test(w io.Writer, name string, f func(t *testing.T)) bool

Activity

  1. added this to the Proposal milestone on May 15, 2019
  2. josharian commented on May 15, 2019

    @josharian
    Contributor

    See also #6511

    There is work in progress now to allow multiple files in the playground, which should make this better yet.

  3. rsc commented on May 28, 2019

    @rsc
    Contributor

    I had no idea that https://play.golang.org/p/LnHfX2yF4Oe worked, but it does. (We should write clearer docs for the playground - @bradfitz will file a bug.)

    Given that https://play.golang.org/p/LnHfX2yF4Oe does work, @rogpeppe, is there still much rationale for adding testing.Test?

  4. bradfitz commented on May 28, 2019

    @bradfitz
    Contributor

    I filed #32294

  5. rsc commented on May 29, 2019

    @rsc
    Contributor

    Looking at this again I am surprised that GitHub says I closed this. I suspect I clicked the wrong button again. I intended to leave it open for @rogpeppe to respond.

  6. reopened this on May 29, 2019
  7. rogpeppe commented on May 29, 2019

    @rogpeppe
    ContributorAuthor

    Thanks Russ - the close did feel a little sudden :) The playground was my main motivation behind raising this issue, so I think it's OK to close this issue. I might remember another use case in time though.

  8. locked and limited conversation to collaborators on May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions