-
Notifications
You must be signed in to change notification settings - Fork 6k
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
How to simulate ExoPlayer in unit tests ? #6328
Comments
We are having a bunch of such tests in ExoPlayerTest. It uses the ExoPlayerTestRunner from thes testutil module you are mentioning above. The test runner internally creates a TestExoPlayer which extends from SimpleExoPlayer. The test ExoPlayer instance can be wired up with various FakeXYZ components. To trigger events you can set up a ActionSchedule (see ExoPlayerTest for examples) which issues call to the ExoPlayer instance. Your test asserts can then verify whether a given state has been changed or whether expected methods have been called. |
The general approach should be as Marc described above. Please have a look at our More specific comments:
This approach is using a real player. So all events are dispatched exactly the same way as in non-test cases.
There is no issue with using
That one is not that easy to solve. We usually use some kind of |
Closing due to lack of activity. |
[REQUIRED] Searched documentation and issues
testutils
andtestutils_robolectric
.testutils
andtestutils_robolectric
as artifacts[REQUIRED] Question
I am using ExoPlayer to play audio with a background service controlled via a Media Session.
Since I am doing TDD, I'd like to cover most code with unit and integration tests. I have an ExoPlayer instance that is injected into my service components with Dagger 2, so that any class that communicates with the player has it as a constructor parameter.
Here is my question : how should I mock/fake
ExoPlayer
, so that I can test components that use it in isolation ? I know thatExoPlayer
is an interface and therefore can be mocked with any mocking framework but this only works for simple interactions and mockingPlayer.EventListener
callbacks is rather hard. For that purpose, something like aFakeExoPlayer
seems more appropriate.What I need is a
FakeExoPlayer
, or aSimpleExoPlayer
with fake components that:Player.EventListener
events immediately on the test thread,ConcatenatedMediaSource
.Here are some things I thought of to solve the question:
ExoPlayer
, dispatchingPlayer.EventListener
events to observers myself inprepare
,seekTo
,setPlayWhenReady
methods. That's a lot of work and it's not ensured to have the same behavior as a realExoPlayer
implementation (don't mock classes you don't own !).testutils
projects. While those components looks really helpful in testingExoPlayer
itself, I struggle to find how to use them for my use case, i.e. simulatingExoPlayer
behavior to test an external component.DataSource.Factory
, I'd be able to produce fakeMediaSource
s to feed theConcatenatingMediaSource
created in player preparation code. I think the new Playlist API described in Top level playlist API for ExoPlayer #6161 should make it easier to test media playlist use cases.Big thanks in advance.
The text was updated successfully, but these errors were encountered: