Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Just run single test instead of the whole suite?

Tags:

go

I have a test suite for a Go package that implements a dozen tests. Sometimes, one of the tests in the suite fails and I'd like to re-run that test individually to save time in debugging process. Is this possible or do I have to write a separate file for this every time?

like image 751
lang2 Avatar asked Sep 29 '14 03:09

lang2


People also ask

How do you only run one test in jest?

It's in the Jest documentation. Another way is to run tests in watch mode, jest --watch , and then press P to filter the tests by typing the test file name or T to run a single test name.

How do I run a specific test file in go?

Go provides the go test command for running the unit tests in a project. Running this command will ordinarily run the whole test suite, but you can limit it to only a specific file or test. If you run go test , it will run both the TestFactorial and TestSquare functions.

How do I run a test from command line?

To run your tests in this mode, run go test in your project's root directory. In the package list mode, go test compiles and tests each package listed as arguments to the command. If a package test passes, go test prints only the final 'ok' summary line. If a package test fails, go test prints the complete test output.


2 Answers

Use the go test -run flag to run a specific test. The flag is documented in the testing flags section of the go tool documentation:

-run regexp     Run only those tests and examples matching the regular     expression. 
like image 189
Simon Fox Avatar answered Oct 18 '22 16:10

Simon Fox


Given a test:

func Test_myTest() {     //... } 

Run only that test with:

go test -run Test_myTest path/to/pkg/mypackage 
like image 27
Cory Klein Avatar answered Oct 18 '22 15:10

Cory Klein