# How do you Unit Test your Servlets?

**URL:** <https://community.developer.atlassian.com/t/how-do-you-unit-test-your-servlets/6894>\
**Category:** Bitbucket Server\
**Tags:** bitbucket-server, testing, junit\
**Created:** [July 31, 2017, 3:31pm UTC](https://community.developer.atlassian.com/t/how-do-you-unit-test-your-servlets/6894 "2017-07-31T15:31:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![srand](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@srand](https://community.developer.atlassian.com/u/srand)\
**Post date:** [July 31, 2017, 3:31pm UTC](https://community.developer.atlassian.com/t/how-do-you-unit-test-your-servlets/6894/1 "2017-07-31T15:31:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bturner](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/bturner/32/35993_2.png) [@bturner](https://community.developer.atlassian.com/u/bturner)\
**Post date:** [August 4, 2017, 1:24am UTC](https://community.developer.atlassian.com/t/how-do-you-unit-test-your-servlets/6894/2 "2017-08-04T01:24:34Z")

</div>

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?

- [stash-archive](https://bitbucket.org/atlassian/stash-archive/src)
- [stash-auto-unapprove-reviewers](https://bitbucket.org/atlassian/stash-auto-unapprove-plugin/src)

---

<div class="post-metadata">

**Author:** ![srand](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@srand](https://community.developer.atlassian.com/u/srand)\
**Post date:** [August 9, 2017, 5:30pm UTC](https://community.developer.atlassian.com/t/how-do-you-unit-test-your-servlets/6894/3 "2017-08-09T17:30:07Z")

</div>

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