Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Allow running pickle on unit tests #18

Merged
merged 16 commits into from
Mar 9, 2019
Merged

Allow running pickle on unit tests #18

merged 16 commits into from
Mar 9, 2019

Conversation

fourlastor
Copy link
Owner

No description provided.

README.md Outdated
strictMode = false // activate/deactivate strict mode (optional, defaults to true)
strictMode = false // activate/deactivate strict mode (defaults to true)
androidTest = true // enables pickle on androidTest (defaults to true)
unitTest = true // enables pickle on unit tests (defaults to false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope but I have some feedback about this.

People generally tend to copy paste what they saw. When we first implementing, we just copy pasted here and that means strictMode was false. We couldn't figure out what's wrong since no tests were generated. (We had missing steps).

I think it is a good idea to keep the example to defaults even though you say defaults to false next.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it now cause it's a very good point d3e33eb

project.plugins.all {
when (it) {
project.plugins.all { plugin ->
when (plugin) {
is LibraryPlugin -> {
project.extensions.findByType(LibraryExtension::class.java)?.run {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you can do

project.extensions.findByType(TestedExtension::class.java)?.run {

here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will enable us to merge 2 branches. And also probably will support other plugins like instant-apps, dynamic-delivery etc.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point but it requires a bit more testing, I'll open an issue

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely makes sense

@@ -151,7 +183,7 @@ class PicklePlugin : Plugin<Project> {
*
* Remove this when we want to only support Android Gradle Plugin 3.3 and above.
*/
private fun setupDependency(task: GenerateTask, variant: TestVariant) {
private fun setupDependency(task: GenerateTask, variant: BaseVariant) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is called for both tasks, accessing mergeAssets causes

Caused by: kotlin.UninitializedPropertyAccessException: lateinit property mergeAssetsTask has not been initialized

The dependency should be different for unit tests.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're very right 🤦‍♂️ my bad, forgot about this one

@tasomaniac
Copy link
Collaborator

I've tested this with our project. I had lots of other problems with Robolectric but that is out of scope. This seems to work perfectly. 👍 It was able to generate code for unit tests.

I have a suggestion for the extension. What about something like below:

androidTest {
    enabled = true
    featuresDir = ....
}
unitTest {
   enabled = true
   featuresDir = ....
}

@fourlastor
Copy link
Owner Author

@tasomaniac do you mean

pickle {
  androidTest { }
  unitTest { }
}

?

@tasomaniac
Copy link
Collaborator

Exactly 👍 It is just an idea.

@fourlastor
Copy link
Owner Author

It does sound good! I'll give it a try this weekend 👍

@fourlastor fourlastor merged commit 71723a5 into master Mar 9, 2019
@fourlastor fourlastor deleted the support-unit-tests branch March 9, 2019 14:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants