-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Break out test into subtests. #540
Break out test into subtests. #540
Conversation
I'm going to let @nywilken review and merge this, but had a small unrelated comment. It looks like GitHub doesn't recognize the email that you've used to commit with. You can tweak this in https://github.com/settings/emails without making your email visible on your profile. |
7d9cf66
to
dd49a1e
Compare
This allow the test tools to show individuals reports. Other tests in the CLI uses the pattern of having a slice of input+expectedOutput+name, they may also benefit form this solution (I can make the change if you like this commit)
dd49a1e
to
17a87d0
Compare
I think it's ok now :) |
Indeed! Nicely done 🌷 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think breaking these up into subtest makes sense. As you said in the previous PR it helps to see which is failing and run individual tests.
Nice work on the split. I left some comments pertaining to variable naming. For future commits or in this one would it make sense to change the descriptions so that they are a bit consistent? Making it easy to use go test -run=
cmd/configure_test.go
Outdated
|
||
return func(t *testing.T) { | ||
var cmdTest *CommandTest | ||
cmdTest = &CommandTest{ | ||
Cmd: configureCmd, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can drop the var cmdTest ...
above and use the short variable declaration here.
cmd/configure_test.go
Outdated
@@ -7,76 +7,86 @@ import ( | |||
"github.com/stretchr/testify/assert" | |||
) | |||
|
|||
type testDefinition struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about calling this type testCase
? testDefinition is a bit vague
cmd/configure_test.go
Outdated
expectedAPICfg *config.APIConfig | ||
}{ | ||
{ | ||
tests := []testDefinition{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testCases as a slice of testCase
cmd/configure_test.go
Outdated
desc: "It gets the default API base URL.", | ||
args: []string{"fakeapp", "configure"}, | ||
existingAPICfg: &config.APIConfig{}, | ||
expectedAPICfg: &config.APIConfig{BaseURL: "https://v2.exercism.io/api/v1"}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
cmdTest := &CommandTest{ | ||
for _, definition := range tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s hard to make the distinction on the context of definition as we enter the makeTest func. Maybe it’s because I’m used to seeing it but testcase seems easier to wrap my head around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with all you comment and made the change locally. Will commit soon, thank you.
Also in the meantime I needed to do the same modification on another test (TestDetectPathType). Would you rather avec separate branch/PR for each test that can benefit from this pattern, or separate commit all in the same branch ? (there are 21 tests using testCases)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, what do you favor in Go for naming a variable when the abvious name is the variable type ? I've seen func xx(testCase testCase)
and func xx(tc TestCase)
, and others (pre/postfixing type or variable). What do you favor in this project ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say favor. We generally lean towards readability and consistency. xx(testCase testCase)
stomps out the type so I would not recommend that. Seeing as makeFunc is essentially a method of testCase, which could also be written as func (tc testCase) makeTest() func(*t.Testing)
I would think that tc
as the name is sufficient, an alternative is testcase
as a mixed case is not an option here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in the meantime I needed to do the same modification on another test (TestDetectPathType). Would you rather avec separate branch/PR for each test that can benefit from this pattern, or separate commit all in the same branch ? (there are 21 tests using testCases)
If they are the same type of change than one PR can work. I ask that you commits be broken down per test file (no mixing between configure_test, workspace_test, etc) so that we can review each commit without having to revisit already reviewed items. Please let me know what you think or my ask is not clear.
Thanks again for all your effort with the CLI.
@FabienTregan is there anything else I can help with on this PR? There’s no rush; I want to make sure that you are getting the feedback you need to get this merged. Cheers! |
723add0
to
1ce53b9
Compare
The same pattern can be applyed in those test files :
|
There is currently no description for the tests: only in and expected out values,
Done for now \o/ It makes sens to wait for #539 to be merged before working on workspace/workspace_test.go |
This is looking good. Having the comments actually turned into test case descriptions is a bonus within this refactor. I’ll take another pass once behind a machine to get this merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FabienTregan overall this looks good thank you. I found a few inconsistencies with testNames using desc
vs string concatenation. Nothing major and I would be willing to merge and address later as you already have a PR for solving the really problem of fixing tests on Windows. Let me know if you are okay with defering or if you want to make changes after reading my comments.
assert.NoError(t, err, name) | ||
assert.Equal(t, acceptable, ok, name) | ||
for name, acceptable := range testCases { | ||
testName := name + " should " + notIfNeeded(acceptable) + "be an acceptable name." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a fast follows to this we should replace testName generation with a desc field in the testCases slice. This way we can specify test cases with -run=
easier.
} | ||
} | ||
|
||
func notIfNeeded(b bool) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this a little confusing at first, but I get it. I think for future state we should add a desc field to the testCases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's a quick hack because the original code, instead of using a []struct input {input, expected_output}
uses a map with a (string) key as the input value, and the value as the expected output.
I think this can just be replaced with the pattern that is used elsewhere, then it would be easy to add a description field to the struct, but I was not.
@FabienTregan I am ready to merge this PR. I see you made a change since my last review yesterday evening. Do you still want to make more changes? I took your last comment to mean that you will not refactor other tests at this time. Everything here looks good. Like I said we can refactor further once we have Windows tests rebases. Let me know. |
No, it's ok, I am done :)
----- Mail original -----
De: "Wilken Rivera" <[email protected]>
À: "exercism/cli" <[email protected]>
Cc: "Fabien Tregan" <[email protected]>, "Mention" <[email protected]>
Envoyé: Jeudi 21 Juin 2018 13:02:26
Objet: Re: [exercism/cli] Break out test into subtests. (#540)
@FabienTregan I am ready to merge this PR. I see you made a change since my last review yesterday evening. Do you still want to make more changes? I took your last comment to mean that you will not refactor other tests at this time.
Everything here looks good. Like I said we can refactor further once we have Windows tests rebases. Let me know.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub , or mute the thread .
|
This allow the test tools to show individuals reports.
Other tests in the CLI uses the pattern of having a
slice of input+expectedOutput+name, they may also benefit
form this solution (I can make the change if you like this
commit)