Sign in Go Pro


Using a Custom jUnit TestRule

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Up next



Since you will be starting and shutting down the MockWebServer in each test method, you can extract that into a JUnit TestRule to save repetition. This lesson will show you how to do that.

In this lesson you will learn:

  • How to put a MockWebServer into a TestRule
  • How to pass the url from the MockWebServer to the app in a JUnit @Before method
  • How the server starts and stops before each test execution
  • How to access the server object from within the custom TestRule


Please where can I find the source code ?

You need to go PRO to post comments.

Lessons in MockWebServer