-
Notifications
You must be signed in to change notification settings - Fork 53
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
Robolectric sample project #18
Conversation
I've cleaned up the sample now |
I improved the sample to include JUnit4 and JUnit5 tests where code coverage is reported correctly |
Where is sample-robolectric and where is sample_robolectric? Are they the same module. |
I'll take a look later tonight! I'm sure it's a mistake on my part. Should be the same |
@IgorGanapolsky I think it looks alright. The folder is called sample-robolectric (following the naming convention of the project in general) but the package name is sample_robolectric (dash not permitted). Do you have trouble building the project? |
@alixwar You might want to fetch upstream and merge into your repo. Dependency versions were updated yesterday... |
@IgorGanapolsky Thanks for telling me, will do that now |
@IgorGanapolsky I think it should be fine now |
I opened the generated exec file and it's the same result. All tests (JUnit4, JUnit5, Mockito) generate coverage data except for the Robolectric test. Side note: I managed to f*** up the merge so the changes are quite big. Don't look at the changes, rather follow the steps to reproduce after checking out the project. |
Ok, it builds now. One question, what do the tests in sample-robolectric do - just generate coverage report? If that's the case, how to open |
@IgorGanapolsky How to open the |
Ok, found the actul commit, 2-space formatting |
It was probably formatted automatically by Android Studio upon commit. |
Yeah, I'm not sure why this fork has diverged from the upstreams repo (not a Git wizard) but the point is not to get this PR approved but rather to prove that code coverage is not generated properly even using the latest available version of dependencies |
Yeah, sorry about that, that reformatting is on me. Since your sample project is quite isolated from the remainder of the repository (i.e. its own module), it should be fairly easy to merge the upstream back into your fork. That being said, I also see this PR as a proof-of-concept for missing code coverage with Robolectric, hence why I haven't merged it in yet. |
I ran the changes and figured out that it is still not possible to run roboloectric tests with junit5, thus using the robolectric test runner. Any suggestions how to solve that? |
@joecks |
@alixwar Both. The issue is that there is actually no junit5 test here that is ran with the RobolectricTestRunner. So if I am running any Android related action like accessing the Context this test crash due to a not mocked exception
example is
So I am still not sure how to achieve a combination between robolectric an junit5, any suggestions? |
@joecks I was not able to reproduce your problem (Windows 10). This is the result after running the tests from command line:
|
Well it is not an issue per se with your branch, but right now it is not very useful, because it misses the usage of Android classes with junit5 tests which I thought was the purpose of this exercise, but maybe I was wrong. You can see the issue by adding this line:
in your |
Btw I get this kind of error that is not very surprising:
|
@joecks I think that you have misunderstood the purpose of this branch. The issue that I'm narrowing down is the lack of code coverage when running tests annotated The issue you experience sounds like a pure Robolectric runtime environment issue. Maybe @mannodermaus could comment on this? |
Well maybe I have misunderstood the purpose indeed. I was just confused to see that |
Yes, I can run all the tests in |
But the robolectric test are run with junit4 and not 5, or? |
JUnit5 using the vintage junit4 runner. To get pure JUnit5 support the Robolectric project needs to implement new extensions. But this is a good point that you have, it is not clear that I meant JUnit5 with the legacy runner |
@mannodermaus do you have any inside on how to implement a junit5 robolectric test runner? |
You'd basically have to convert the |
What's the status of this PR and, more importantly, the status of Android + JUnit 5 + Robolectric? |
This PR used to be a proof-of-concept integration of Robolectric against an outdated version of the android-junit5 plugin. It's up to the Robolectric team to provide full support for JUnit 5, which in turn is dependent on a good proposal for this issue on the JUnit 5 repo first. Until a real integration of the two is managed by the respective team, there won't be a canonical sample project in this repo. I'd also like to link this section from Danny's talk on JUnit 5 at this year's Droidcon, because it gives a great overview of the current state of this topic, too. |
After 5 years, Is the state of Roboletric still the same where it doesn't work with Junit5? |
@vincent-paing The main blocker has been resolved from JUnit 5's end in the meantime, but regardless Robolectric still does not work with it. I gave some context in a pinned issue that you can check out – it also has a link to the Robolectric feature request if you would like to read more or chime in. With the disparity between the current state of this repo and the timestamp of this POC PR, I'm taking the liberty to also close it down. 🙇♂️ I'm crossing my fingers that there'll eventually be a time where Robolectric and JUnit 5 will finally be united in harmony. |
I added a sample project based on my own setup:
There is a Robolectric test in the sample project which executes one line of code but I'm not able to get any code coverage
Steps to reproduce:
gradlew testDebug
sample-robolectric\build\jacoco\junitPlatformTestDebug.exec
(In IntelliJ you can open an .exec-file with ctrl+alt + F6), it shows coverage for all lines of code inde.mannodermaus.gradle.plugins.android_junit5.sample_robolectric.Foo
except for the methodjunit4robolectric()