This isn't really any different from how you'd unit test any other code -- create an instance of your connector/task, setup any mocks you need, and then exercise various scenarios. If you want some examples, check any of the Confluent connector repositories, e.g. here are the tests for the Elasticsearch connector:
https://github.com/confluentinc/kafka-connect-elasticsearch/tree/master/src/test/java/io/confluent/connect/elasticsearch. Aside from getting good coverage of the body of the code, it's worth trying to test various scenarios & configs. For example, we have unit tests in the HDFS and S3 connectors covering the different configs we have for how to decide when to close and commit a file.