Skip to content
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

Merged
merged 16 commits into from
Jun 21, 2018

Conversation

FabienTregan
Copy link
Contributor

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)

@kytrinyx
Copy link
Member

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.

@FabienTregan FabienTregan force-pushed the breakout_test_configure branch 2 times, most recently from 7d9cf66 to dd49a1e Compare June 11, 2018 09:06
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)
@FabienTregan FabienTregan force-pushed the breakout_test_configure branch from dd49a1e to 17a87d0 Compare June 11, 2018 09:20
@FabienTregan
Copy link
Contributor Author

I think it's ok now :)

@kytrinyx
Copy link
Member

I think it's ok now

Indeed! Nicely done 🌷

Copy link
Contributor

@nywilken nywilken left a 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=


return func(t *testing.T) {
var cmdTest *CommandTest
cmdTest = &CommandTest{
Cmd: configureCmd,
Copy link
Contributor

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.

@@ -7,76 +7,86 @@ import (
"github.com/stretchr/testify/assert"
)

type testDefinition struct {
Copy link
Contributor

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

expectedAPICfg *config.APIConfig
}{
{
tests := []testDefinition{
Copy link
Contributor

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

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor Author

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 ?

Copy link
Contributor

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.

Copy link
Contributor

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.

@nywilken
Copy link
Contributor

nywilken commented Jun 16, 2018

@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!

@FabienTregan FabienTregan force-pushed the breakout_test_configure branch from 723add0 to 1ce53b9 Compare June 16, 2018 22:37
@FabienTregan
Copy link
Contributor Author

FabienTregan commented Jun 16, 2018

@nywilken No it's ok, I think I'll be done tomorrow morning for this one (paris time).

I only refactored the tests I needed to reach a first milestone of PR #539, but now it's done I'll get back to it.

Thanks to you and @kytrinyx , I really leant a lot this week and coding was fun :)

@FabienTregan
Copy link
Contributor Author

FabienTregan commented Jun 16, 2018

The same pattern can be applyed in those test files :

  • api/client_test.go
  • cli/cli_test.go
  • cmd/configure_test.go
  • cmd/download_test.go
  • cmd/upgrade_test.go
  • cmd/version_test.go
  • comms/question_test.go
  • comm/selection_test.go (tests)
  • comm/selection_test.go (things)
  • config/track_test.go
  • config/user_config_test.go
  • config/user_config_windows_test.go
  • workspace/path_type_test.go
  • workspace/solution_test.go (1)
  • workspace/solution_test.go (2)
  • workspace/transmission_test.go
  • workspace/workspace_test.go (1)
  • workspace/workspace_test.go (2)
  • workspace/workspace_test.go (3)
  • workspace/workspace_test.go (4)

@FabienTregan
Copy link
Contributor Author

Done for now \o/

It makes sens to wait for #539 to be merged before working on workspace/workspace_test.go

@nywilken
Copy link
Contributor

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.

Copy link
Contributor

@nywilken nywilken left a 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."
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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.

@nywilken nywilken changed the title Breaks out TestConfigure into subtests. Break out test into subtests. Jun 21, 2018
@nywilken
Copy link
Contributor

@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.

@FabienTregan
Copy link
Contributor Author

FabienTregan commented Jun 21, 2018 via email

@nywilken nywilken merged commit 818bc53 into exercism:nextercism Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants