Stay organized with collections
Save and categorize content based on your preferences.
MockService
open class MockService
A mock android.app.Service
class.
Provided for use by android.test.ServiceTestCase
.
Summary
Public methods |
open static Unit |
|
Public methods
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[],[],null,["# MockService\n\nAdded in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nMockService\n===========\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/test/mock/MockService \"View this page in Java\") \n\n```\nopen class MockService\n```\n\n|---|------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.test.mock.MockService](#) |\n\n*** ** * ** ***\n\n| **This class was deprecated in API level 28.**\n|\n| Use a mocking framework like [Mockito](https://github.com/mockito/mockito). New tests should be written using the [Android Testing Support Library](https://developer.android.com/tools/testing-support-library/index.html).\n\nA mock [android.app.Service](../../app/Service.html#) class.\n\nProvided for use by `android.test.ServiceTestCase`.\n\nSummary\n-------\n\n| Public methods ||\n|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open static [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [attachForTesting](#attachForTesting(android.app.Service,%20android.content.Context,%20kotlin.String,%20android.app.Application))`(`service:` `[Service](../../app/Service.html#)!`, `context:` `[Context](../../content/Context.html#)!`, `serviceClassName:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `application:` `[Application](../../app/Application.html#)!`)` \u003cbr /\u003e |\n\nPublic methods\n--------------\n\n### attachForTesting\n\nAdded in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun \u003cT : Service!\u003e attachForTesting(\n service: Service!, \n context: Context!, \n serviceClassName: String!, \n application: Application!\n): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*"]]