2014-09-29 16 views
7

Ho una suite di test per un pacchetto Go che implementa una dozzina di test. A volte, uno dei test nella suite non riesce e mi piacerebbe rieseguire il test individualmente per risparmiare tempo nel processo di debug. È possibile o devo scrivere un file separato per questo ogni volta?Basta eseguire un test singolo invece dell'intera suite?

+1

'go run - run regexp' eseguirà solo test il cui nome corrisponde all'espressione regolare. [docs] (https://golang.org/cmd/go/#hdr-Description_of_testing_flags) –

+1

Grazie. Ma dovrebbe essere "vai a testare" – lang2

risposta

17

Utilizzare il flag go test -run per eseguire un test specifico. La bandiera è documentato in la testing flags section della documentazione go tool:

-run regexp 
    Run only those tests and examples matching the regular 
    expression. 
1

Nel caso qualcuno che sta utilizzando quadro Ginkgo BDD per Go avrà lo stesso problema, questo potrebbe essere realizzato in tale contesto contrassegnando spec test come concentrato (see docs), anteponendo le funzioni F prima di It, Context o Describe.

Quindi, se avete specifiche come:

It("should be idempotent", func() { 

si riscrive come:

FIt("should be idempotent", func() { 

e verrà eseguito esattamente che uno spec:

[Fail] testing Migrate setCurrentDbVersion [It] should be idempotent 
... 
Ran 1 of 5 Specs in 0.003 seconds 
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 4 Skipped 
Problemi correlati