How do you Unit Test your Servlets?

Hey all,

I am starting to write tests for my Bitbucket plugin. I am new to the “official” testing world (adding tests as a part of a build process).

What is the “Atlassian” way or general way to test Servlet classes? I have my plugin directory structure setup correctly for the atlassian sdk test command to work, I now need actual tests.

Any guidance/adivce/examples welcomed.

Unit tests for a Servlet in an add-on wouldn’t be any different than any other unit tests.

If you want more end-to-end (read: integration) testing, then the next question is what type of output your servlet is generating. If it’s a webpage, you could add a browser test using Selenium. Otherwise, for more “plain” responses (text, JSON, etc.), you could treat it as a REST endpoint (though ideally it would be a REST endpoint instead, at that point).

Here are a couple open-source plugins that have been curated by Bitbucket Server team members. They’ve got unit tests (for the unapprove reviewers plugin), REST tests (both) and (for the archive plugin) browser tests. Perhaps they’ll help?


Thanks Bryan. Let me check out the examples you sent.