Closed thuan1412 closed 9 months ago
For 1 an alterative is snippets included in go.nvim for 2, it is by design, as the plugin need to know the name of testcase to run a specific test. But you do not need to put the cursor on the name, anywhere inside the testcase should be fine. For table driven test you need to put cursor on the table entry to run a specific test case.
GoTestSubCase
where I put the cursor outside of the testcase name, but it does not run the 1 + 2 = 3
testcase, instead, it run the whole Test_add
function.
package add
import "testing"
func Testadd(t *testing.T) { type args struct { a int b int } tests := []struct { name string args args want int }{ { name: "1 + 2 = 3", args: args{1, 2}, want: 3, }, } for , tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := add(tt.args.a, tt.args.b); got != tt.want { t.Errorf("add() = %v, want %v", got, tt.want) } }) } }
Yes, I know it is a bit painful. I will need to update the AST parser to handle TestSubCase.
Currently, the
GoTestSubCase
command has two small problems:We should resolve these two problems to increase productivity when writing tests.