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

Is it possible to run Robolectric with @RunWith(Enclosed.class)? #2946

Closed
sureshjoshi opened this issue Mar 5, 2017 · 3 comments
Closed
Milestone

Comments

@sureshjoshi
Copy link

In some JUnit tests, I would like to use the test runner Enclosed for nice grouping of tests in a file (and do be able to use a clean whenXYZ, shouldABC naming convention).

Would it be possible to do the same in Robo? If so, how would I go about it? Do I need to create a custom test runner ala ParameterizedRobolectricTestRunner?

@jongerrish jongerrish modified the milestone: to prioritize Mar 14, 2017
@noelmansour
Copy link

noelmansour commented Mar 15, 2017

It's pretty much the same as using the Enclosed test runner on its own. You just have to add @RunWith(RobolectrTestRunner.class) to one of the static inner classes. Here's an example of how you would do this.

@RunWith(Enclosed.class)
public class FooServiceTest {

  // All tests will need to extend this one
  @Ignore
  @RunWith(RobolectricTestRunner.class)
  @Config(constants = BuildConfig.class)
  public abstract static class GivenRobolectricContext {
    ServiceController<FooService> serviceController;

    @Before
    public void givenRobolectricContext() {
      serviceController = Robolectric.buildService(FooService.class).create();
    }
  }

  public static class GivenFooService extends GivenRobolectricContext {
    // put your context specific tests here.
  }
}

@philbrown-mdt
Copy link

Any update on this?

@utzcoz
Copy link
Member

utzcoz commented Dec 30, 2022

See #7873.

@utzcoz utzcoz closed this as completed Dec 30, 2022
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

5 participants