-
Notifications
You must be signed in to change notification settings - Fork 319
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
Parameterized Android tests on Robolectric could not be run #283
Comments
Hey @tiwiz So, this is kind of tough right now...
Long term Nitrogen will solve this as we won't need any custom JUnit4 test runners to bootstrap Robolectric or Instrumentation tests (which will be done via N2 itself. So... what can we do in the meantime? I chatted with the team and we think creating a ParameterizedAndroidJUnit4.class which will would replace RobolectricParameterizedTestRunner.class and also delegate to the regular Parameterized.class to work on-device too. This helps with our goal of consolidating Robolectric test runners into AndroidX Test and it will also remain compatible (although not necessary) once Nitrogen + Sheep device are shipped. What do you think about having a go at implementing this ParameterizedAndroidJUnit4 test runner? We're not going to get to it right very soon, but we'd provide full support in guidance and code reviews and getting it into a release. You'd get all the glory :-) |
Thanks for clarifying! I'll give it a shot :-) |
@jongerrish Appreciate the thoughtful response here. Is there any update on the release of N2? Anxiously waiting to get my hands on it. Would love to help contribute if any of it is open source. |
@mrk-han Hey Mark, the team is still working hard on N2 and we're trialing it internally, mainly the effort to externalize it has been dependent on the integration into studio which is the next phase we're working on presently, because its such a fundamental change its something we really need to make sure we get right. |
@tiwiz awesome - feel free to ping me if you need anything for this! |
Hi @tiwiz were you able to make any progress on this issue? |
Unfortunately I was not 😶 overwhelmed with work stuff, but I plan to do it ASAP, hopefully before the summer |
And here we are one year later 😢 |
Here's how you do it as per 4/06/2020 @RunWith(ParameterizedRobolectricTestRunner::class)
@Config(sdk = [Build.VERSION_CODES.O_MR1] )
class CypherUnitTest(
val param1: Double,
val param2: Double,
val param3: Double,
val param4: String,
val param5 String
) {
companion object {
private fun mold(
val param1: Double,
val param2: Double,
val param3: Double,
val param4: String,
val param5 String
) = arrayOf(param1, param2, param3, param4, param5)
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters
fun testCases() = listOf(
mold(…),
mold(…),
mold(…)
)
}
@Test
fun yourTest(){ … }
} |
That worked for me. Looks like this issue could be closed? |
If those tests only run |
Here is an ugly hack to get it to work (while we wait for something better...). I provide the recipe instead of the code as I'm not sure about the license implications:
Done. |
@jongerrish @utzcoz I could give it a shot once back from holidays, in April. I believe the challenging part is to make it work for instrumented tests, @alixwar workaround should, with some adjustments, suffice for getting it working with robolectric |
@sergio-sastre @alixwar Maybe you can check https://android-review.googlesource.com/c/platform/platform_testing/+/2623172, the CL for |
Actually I had something simpler in mind that's what I am using in this ParameterizedRobolectricSharedTestRunner for my library and it is working: Since the main issue is that the current ParameterizedRobolectricTestRunner requires its own Parameters annotation i.e. @ParameterizedRobolectricTestRunner.Parameters
I understand that's not enough to avoid breaking changes but one could write the ParameterizedRobolectricTestRunner to support both annotations. But... just my 2 cents |
Description
I had the need to test a specific feature of a paging component that used Room, and I needed to use a real in memory version of Room, so I needed the
Context
. Since the tests cases needed to cover different inputs, but the logic was the same, I intended to use Parameterized tests from JUnit 4Steps to Reproduce
Open the
SimpleParameterizedTest.kt
class and try to execute it with Robolectric.Actual Results
If we run the suite with
@RunWith(AndroidJUnit4::class)
, we get the following error:If we run the suite with
@RunWith(Parameterized::class)
, we instead get the following error:AndroidX Test and Android OS Versions
I am trying with the following dependencies
Link to a public git repo demonstrating the problem:
GitHub Repository
The text was updated successfully, but these errors were encountered: