How can i test my custom Kibana Plugin?

Most of our functional UI tests (Selenium tests) load test data into Elasticsearch using the es_archiver

For example, in this discover test it uses
await esArchiver.load('discover');

Which is loading the set of data which is checked-in here; https://github.com/elastic/kibana/tree/master/test/functional/fixtures/es_archiver/discover

You can run the es_archiver from the command line to save some data you created in Elasticsearch by whatever means you want. And then in your test you would load that data. If it's time-based data (typically is) then in your test you would always set the Kibana timepicker to the same exact time so you always get the same results on that data. Like await PageObjects.header.setAbsoluteRange(fromTime, toTime);

If you're creating a new plugin, I would create a new Page Object file for the methods needed to access the objects in your plugin page.

You would typically run the UI tests by starting the Elasticsearch and Kibana server like
npm run test:ui:server
and then running the tests like;
node scripts/functional_test_runner

See https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md

Regards,
Lee