Barista icon indicating copy to clipboard operation
Barista copied to clipboard

Offer a quick way to disable the BaristaRule retries

Open rocboronat opened this issue 6 years ago โ€ข 18 comments

The BaristaRule is great, but when you are trying to develop a complex test, you want to just crash the test when it fails. "Ok, it doesn't work, I want to see the Espresso Exception... but I need to wait 10 fails :ยทD"

rocboronat avatar Oct 25 '17 16:10 rocboronat

Feel free to add it!

Sloy avatar Oct 30 '17 15:10 Sloy

Same! ๐Ÿฅ‡

rocboronat avatar Oct 31 '17 16:10 rocboronat

Any hint about the best or desirable approach?

EsteveAguilera avatar Nov 13 '17 19:11 EsteveAguilera

IMHO, this is a great way to use it:

@Rule public BaristaRule<MyActivity> baristaRule = BaristaRule.create(MyActivity.class).withoutRetries();

rocboronat avatar Nov 13 '17 19:11 rocboronat

Mmm... what about let the developers choose the number of max attempts?

EsteveAguilera avatar Nov 13 '17 19:11 EsteveAguilera

How 'bout

@Rule
public BaristaRule baristaRule = BaristaRule.for(MyActivity.class)
  .withRetries(5)
  .clearingSharedPreferences()
  .clearingDatabases()
  .clearingFiles()
  .withAllPermissions()
  .build();

But I'm still missing a clean way to setup the internal rules like ClearFiles and ClearDatabases.

Sloy avatar Nov 13 '17 19:11 Sloy

Actually, focusing on the needed, the reason why I opened the issue (and I think that most devs need) is to just disable the retries when developing a new test.

@EsteveAguilera IMHO, the answer to the question is that it's a detail that is not too important. Or at least, right now :ยทD For me, I don't care if it's 5 or 10 retries. The only thing I need is to disable it when I'm developing a new test.

rocboronat avatar Nov 13 '17 19:11 rocboronat

Ok @rocboronat , I see what you mean. Maybe the title of the issue is not too descriptive, one thing is 'configure' and another one 'disable retries' ๐Ÿ˜

EsteveAguilera avatar Nov 13 '17 20:11 EsteveAguilera

Totally :ยทD Let's change the title

rocboronat avatar Nov 13 '17 20:11 rocboronat

Sorry for the confusion, by the way ๐Ÿ‘‰ ๐Ÿ‘ˆ

rocboronat avatar Nov 13 '17 20:11 rocboronat

BTW @rocboronat, if what you need is to disable retries for some new test while developing, you can overwrite the default retries by annotating the specific method:

@Test
@AllowFlaky(attempts = 1)
public void someNewTest() throws Exception {
}

Does this solve your needs in this issue @rocboronat?

Sloy avatar Nov 14 '17 10:11 Sloy

Toc toc @rocboronat. Does my last comment help with your pain? Or should we revisit the solutions?

Sloy avatar Jun 28 '18 09:06 Sloy

Let's close the issue because the author doesn't answer. Whow, that's me! :ยทD

Thanks a lot for the solution, @Sloy

rocboronat avatar Aug 27 '18 20:08 rocboronat

I need the feature again... ๐Ÿ™ˆ

rocboronat avatar Mar 09 '19 20:03 rocboronat

We need this feature too. I would be happy to help in any way I can ๐Ÿ‘

Phixyn avatar Mar 13 '19 11:03 Phixyn

@rocboronat Cool! Does my comment from 14 Nov 2017 help with your new pain? :P

In a serious note, I would encourage you to use a custom rule instead of the Barista rule. It's great for quickly setting up UI tests, but falls short when you need more flexibility. That's what we started to do at Schibsted.

Sloy avatar Mar 13 '19 16:03 Sloy

That was my opinion, and if you don't like it... I have another!

Maybe adding an optional boolean parameter to the Rule constructor to enable/disable the flaky repetitions?

This is what we do at our project:

val DEFAULT_FLAKY_ATTEMPTS = BuildConfig.IS_CI ? 7 : 1
//...
flakyTestRule =FlakyTestRule().allowFlakyAttemptsByDefault(DEFAULT_FLAKY_ATTEMPTS)

That way the repetitions are done on CI builds only, and they are ignored when running tests locally.

The IS_CI constant comes from our build.gradle file like this:

android {
    defaultConfig {
        buildConfigField "boolean", "IS_CI", isTravis.toString()
    }
}

Sloy avatar Mar 13 '19 16:03 Sloy

That's great @Sloy! Wise solution! ๐Ÿ‘

Right now it seems that Firebase Test Cloud is so stable to not need the AllowFlaky feature. We just made a hard copy of the BaristaRule and replaced the 10 with a 1... but it's not an ideal solution. I think that this feature is the only one that needs to be disabled at will. The other magic done by the Rule is so great that (I hope) nobody will need to disable it.

BTW, don't worry about this issue. I'll do something when it would be that important.

rocboronat avatar Mar 15 '19 04:03 rocboronat