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

Support for null strings #4

Closed
shafty023 opened this issue Apr 22, 2021 · 3 comments
Closed

Support for null strings #4

shafty023 opened this issue Apr 22, 2021 · 3 comments
Assignees

Comments

@shafty023
Copy link

Any tips/suggestions for getting null as a value? I know JSR won't allow null to be passed in because it's not a constant but is there any clean way of doing it besides generating my own TestParameterValuesProvider for every parameter that needs to support null?

// Doesn't work
@Test
fun someTest(@TestParameter(value = [null, "", "foo"]) param: String) {
    ...
}

// Ugly bc you'd have to define the provider for every String argument in every test method
@Test
fun someTest(@TestParameter(valuesProvider = FooProvider::class) param: String) {
    ...
}

class FooProvider : TestParameter.TestParameterValuesProvider {
    override fun provideValues(): MutableList<String?> {
        return mutableListOf(null, "", "foo")
    }
}
@nymanjens nymanjens self-assigned this Apr 23, 2021
@nymanjens
Copy link
Collaborator

Hi Daniel,

At the moment, your workaround seems to be the best solution for getting a null value, but I agree it's not ideal.

The following change would make it a lot easier to test for null values:

@Test
fun someTest(@TestParameter(value = ["null", "", "foo"]) param: String) {
   // "null" wouldn't be interpreted as String but as null value
    ...
}

I've implemented this and I'm now re-running all Google tests to see if any existing code is relying on a "null" string being "null". If this turns out to work, I'll push it onto a new release.

@nymanjens
Copy link
Collaborator

This change has been released in v1.3

@shafty023
Copy link
Author

@nymanjens Thanks! This is exactly what I needed. You rock.

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

No branches or pull requests

2 participants