Customer.io
  • Platform
  • Pricing
  • Resources
  • Company
  • Sign In
Request Demo
  • Features
  • Pricing
  • Customers
  • Docs

Request Demo Sign In
  • Documentation
    • Getting Started
    • Accounts & Workspaces
    • People
    • Segmentation
    • Campaigns & Workflows
    • Message Channels
    • Liquid & Personalization
    • Metrics
    • Data & Integrations
  • API
    • API Reference
    • Reporting Webhooks
    • Integration Libraries
  • SDK
    • iOS
    • Android
  • Release Notes
Android
  • Get Started
  • Identify people
  • Track events
  • Push notifications
  • Rich push notifications
  • Test support
  • Migrate from an earlier version
  • Changelog
    • Get Started
    • Identify people
    • Track events
    • Push notifications
    • Rich push notifications
    • Test support
    • Migrate from an earlier version
    • Changelog
    • Get Started
    • Identify people
    • Track events
    • Push notifications
    • Rich push notifications
    • Test support
    • Migrate from an earlier version
    • Changelog
    • In-app messages

60

Test support

The SDK makes it easy to write unit, integration, UI, or other types of automated tests in your code base. We designed our SDK with first-class support for automated testing, making it easy to inject dependencies and perform mocking in your code.

This page is part of an introductory series to help you get started with the essential features of our SDK. The highlighted step(s) below are covered on this page. Before you continue, make sure you've implemented previous features—i.e. you can't identify people before you initialize the SDK!

graph LR getting-started(Install SDK) -->B(Initialize SDK) B --> identify(identify people) identify -.-> track-events(Send events) identify -.-> push(Receive push) identify -.-> rich-push(Receive Rich Push) track-events --> test-support(Handle errors) push --> test-support rich-push --> test-support click getting-started href "/docs/sdk/android/beta/getting-started" click B href "/docs/sdk/android/beta/getting-started/#initialize-the-sdk" click identify href "/docs/sdk/android/beta/identify" click track-events href "/docs/sdk/android/beta/track-events/" click push href "/docs/sdk/android/beta/push" click rich-push href "/docs/sdk/android/beta/rich-push" click test-support href "/docs/sdk/android/beta/test-support" style test-support fill:#B5FFEF,stroke:#007069

Dependency injection

Every SDK class inherits from an interface. Inherited interfaces use a consistent naming convention: <NameOfClass>Instance. For example, the CustomerIO class inherits the protocol CustomerIOInstance.

If you want to inject a class in your project, it could look something like the example below.

class ProfileRepository(private val cio: CustomerIOInstance) {
    
    // Now, you can call any of the `CustomerIO` class functions with `this.cio`!
    suspend fun loginUser(email: String, password: String) {
        // Login the user to your system...

        // Then, identify the profile with Customer.io:
        cio.identify(email)
    }
}

val cio = CustomerIO.instance()
val repository = ProfileRepository(cio)

Mocking

Every SDK class inherits from an interface. Inherited interfaces use a consistent naming convention: <NameOfClass>Instance. For example, the CustomerIO class inherits the protocol CustomerIOInstance.

Interfaces are really easy to mock with mocking frameworks such as Mockito.

Here’s an example test class showing how you would test your ProfileRepository class.

class ProfileRepositoryTest {

    private val cioMock: CustomerIOInstance = mock()
    private lateinit var repository: ProfileRepository

    @Before 
    fun setUp() {
        repository = ProfileRepository(cioMock)
    }

    @Test 
    fun test_loginUser(): Unit = runBlocking {
        val givenEmail = "example@example.com"
        val givenPassword = "123"

        // Now, call your function under test:        
        repository.loginUser(givenEmail, givenPassword)

        // You can access many properties of the mock class to assert the behavior of the mock. 
        verify(cioMock, times(1)).identify(givenEmail, givenPassword)
    }
}
Copied to clipboard!
      • Dependency injection
    • Mocking
Latest release
Stable
Is this page helpful?

How can we make it better?

We appreciate your feedback!


Product
  • Features
  • Customer Success
  • Professional Services
  • Pricing
  • Workflows
  • Ad Audience Sync
  • Watch a Demo Video
Resources
  • Documentation
  • Release Notes
  • Customer.io API
  • Getting Started Guide
  • Integrations Catalog
  • Data Export Methods
  • Security and Compliance
Industry
  • SaaS
  • EdTech
  • Two-Sided Marketplaces
  • FinTech
  • Internet of Things (IoT)
  • Subscription Box
  • Media Companies
Company
  • Blog
  • Support
  • Partners
  • Customers
  • About
  • Careers
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Status
  • © Peaberry Software, Inc.