---
schema_version: "1"
id: ddd5fce4bbaf22ac4c5c07369f4b87b8376e54205a878f8c578b5f8f62a0aa9a
title: Test Client Overrides
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-slack-sdk/apex-slack-sdk/guides/test/test_override.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/test_override.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a708566063bc3a7bcf3cf9639e9d66628d9d29c06ee618e49bbfbb3ea08209a8
products:
  - Apex SDK for Slack (Beta)
---
# Test Client Overrides

Test Harness allows test authors to override various clients (AppClient, BotClient, UserClient) when running tests. Test Harness also allows test authors to provide implementations for the Slack API methods without a default implementation by the test harness. Negative testing of Slack APIs is allowed as well.

To mock the clients, the test author must extend from the proper client mock (AppClientMock, BotClientMock, UserClientMock). The tester then provides override implementations for the API methods to mock. The implementation must receive the request payload as the parameter and return a response payload as a result. You can override multiple methods in the same mock, but any methods that aren’t overridden default to the implementation that the test harness provides.

Methods with a default implementation:

- chatPostEphemeral
- chatPostMessage
- conversationsInfo
- usersInfo
- viewsOpen
- viewsPublish
- viewsPush
- viewsUpdate

**note:** If you provide a constructor implementation for your mock client, you must call the super method to insure access to the default api method implementations.

To use the mock implementation it must be set on the Slack State object by calling the proper method in the test.

- [SlackState.setAppClientMock(AppClientMock)](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_testharness.md#testharnessstate-class)
- [SlackState.setBotClientMock(BotClientMock)](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_testharness.md#testharnessstate-class)
- [SlackState.setUserClientMock(UserClientMock)](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_testharness.md#testharnessteam-class)

It’s optional, but recommended, to clear the mock clients after the test finishes by calling the proper methods in the test.

- [SlackState.clearAppClientMock()](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_testharness.md#testharnessstate-class)
- [SlackState.clearBotClientMock()](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_testharness.md#testharnessstate-class)
- [SlackState.clearUserClientMock()](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_testharness.md#testharnessstate-class)

Alternatively you can call [SlackState.clearAllClientMocks()](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_testharness.md#testharnessstate-class) to clear them all at the same time.

## Apex Example

```xquery
@isTest
public class ExampleMockOverrideTest {

    private static Slack.TestHarness testHarness;
    private static Slack.TestHarness.State slackState;

    static {
        testHarness = new Slack.TestHarness();
        slackState = testHarness.getNewSlackState();
    }

    @isTest
    static void testReactionsGet() {
        slackState.setBotClientMock(new MyBotClientMock());
        // run commands, shortcuts, events, etc
        slackState.clearBotClientMock();
    }

    class MyBotClientMock extends Slack.BotClientMock {
        public override Slack.ReactionsGetResponse reactionsGet(Slack.ReactionsGetRequest request) {
            Slack.ReactionsGetResponse response = new Slack.ReactionsGetResponse();
            response.setOk(true);
            Slack.ReactionsGetResponse.Message message = new Slack.ReactionsGetResponse.Message();
            Slack.Reaction reaction = new Slack.Reaction();
            reaction.setName('party');
            reaction.setCount(3);
            List<Slack.Reaction> reactions = new List<Slack.Reaction>();
            reactions.add(reaction);
            message.setReactions(reactions);
            message.setText('Test Reactions Message');
            response.setMessage(message);
            return response;
        }
    }

}
```
