Skip to content

Commit

Permalink
Improving testing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Nov 13, 2017
1 parent d7d26fb commit e695c37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ For more details, explore the subjects below!
backends/asynchttpclient
backends/okhttp
backends/custom
backends/testing


.. toctree::
:maxdepth: 2
:caption: Testing

testing

.. toctree::
:maxdepth: 2
:caption: Configuration
Expand Down
6 changes: 3 additions & 3 deletions docs/backends/testing.rst → docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For example::
val response2 = sttp.post(uri"http://example.org/d/e").send()
// response2.code will be 500

It is also possible to match request by partial function, returning a response. E.g.::
It is also possible to match requests by partial function, returning a response. E.g.::

implicit val testingBackend = SttpBackendStub(HttpURLConnectionBackend())
.whenRequestMatchesPartial({
Expand All @@ -33,7 +33,7 @@ It is also possible to match request by partial function, returning a response.
val response2 = sttp.post(uri"http://example.org/partialAda").send()
// response2.body will be Right("Ada")

However, this approach has one caveat: the responses are not type-safe. That is, the backend cannot match on or verify that the type included in the response matches the response type requested.
This approach to testing has one caveat: the responses are not type-safe. That is, the backend cannot match on or verify that the type included in the response matches the response type requested.

Simulating exceptions
---------------------
Expand All @@ -47,7 +47,7 @@ If you want to simulate an exception being thrown by a backend, e.g. a socket ti
Adjusting the response body type
--------------------------------

If the type of the response body returned by the stub's rules (as specified using the ``.when...`` methods) doesn't match what was specified in the request, the stub will attempt to convert the body to the desired type. This might be useful when:
If the type of the response body returned by the stub's rules (as specified using the ``.whenXxx`` methods) doesn't match what was specified in the request, the stub will attempt to convert the body to the desired type. This might be useful when:

* testing code which maps a basic response body to a custom type, e.g. mapping a raw json string using a decoder to a domain type
* reading a classpath resource (which results in an ``InputStream``) and requesting a response of e.g. type ``String``
Expand Down

0 comments on commit e695c37

Please sign in to comment.