<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>hiquality.dev</title><link>https://hiquality.dev/</link><description>Recent content on hiquality.dev</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 13 May 2026 21:00:00 +0200</lastBuildDate><atom:link href="https://hiquality.dev/index.xml" rel="self" type="application/rss+xml"/><item><title>Getting Started with WireMock</title><link>https://hiquality.dev/posts/getting-started-with-wiremock/</link><pubDate>Wed, 13 May 2026 21:00:00 +0200</pubDate><guid>https://hiquality.dev/posts/getting-started-with-wiremock/</guid><summary>&lt;p&gt;Recently I was conducting internal training on using WireMock for testing web applications — especially the backend. Here I would like to share how to start WireMock and use it in your tests.&lt;/p&gt;
&lt;h2 id="what-is-wiremock"&gt;What is WireMock?&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://wiremock.org/"&gt;WireMock&lt;/a&gt; is a flexible and powerful API mocking tool that allows developers and testers to simulate HTTP-based APIs. It provides a simple and intuitive interface for creating mock APIs, making it easier to test applications that depend on external services. With WireMock, you can create mock responses, simulate various scenarios, and validate the behaviour of your application under different conditions.&lt;/p&gt;</summary><description>&lt;p&gt;Recently I was conducting internal training on using WireMock for testing web applications — especially the backend. Here I would like to share how to start WireMock and use it in your tests.&lt;/p&gt;
&lt;h2 id="what-is-wiremock"&gt;What is WireMock?&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://wiremock.org/"&gt;WireMock&lt;/a&gt; is a flexible and powerful API mocking tool that allows developers and testers to simulate HTTP-based APIs. It provides a simple and intuitive interface for creating mock APIs, making it easier to test applications that depend on external services. With WireMock, you can create mock responses, simulate various scenarios, and validate the behaviour of your application under different conditions.&lt;/p&gt;
&lt;h2 id="when-to-use-wiremock"&gt;When to use WireMock?&lt;/h2&gt;
&lt;p&gt;WireMock was designed to allow testing of web applications by mocking different responses from external APIs they use. It allows me to test more scenarios than would be possible using a production external API.&lt;/p&gt;
&lt;p&gt;In my daily work I usually test asynchronous APIs. In these scenarios, WireMock acts as an HTTP server where my system under test sends callbacks and notifications.&lt;/p&gt;
&lt;p&gt;WireMock helps me solve several problems encountered when testing web applications that depend on external APIs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the external API is unstable, making test results unpredictable;&lt;/li&gt;
&lt;li&gt;the API has low rate limits that are not sufficient for all required tests;&lt;/li&gt;
&lt;li&gt;the API does not exist yet and all we know is the API specification.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To be absolutely sure the application under test works correctly, I also need to perform some end-to-end testing with a real API, because mocks might not match the external API exactly.&lt;/p&gt;
&lt;h2 id="running-wiremock"&gt;Running WireMock&lt;/h2&gt;
&lt;h3 id="necessary-dependencies"&gt;Necessary dependencies&lt;/h3&gt;
&lt;p&gt;To use WireMock in tests, add the following dependency to your Maven project:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-xml"&gt;&amp;lt;dependency&amp;gt;
 &amp;lt;groupId&amp;gt;org.wiremock&amp;lt;/groupId&amp;gt;
 &amp;lt;artifactId&amp;gt;wiremock&amp;lt;/artifactId&amp;gt;
 &amp;lt;version&amp;gt;3.13.2&amp;lt;/version&amp;gt;
 &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or for SBT:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;libraryDependencies += &amp;quot;org.wiremock&amp;quot; % &amp;quot;wiremock&amp;quot; % &amp;quot;3.13.2&amp;quot; % Test
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A WireMock instance can be run in several modes — managed by the test framework, started directly from code, or run in standalone mode.&lt;/p&gt;
&lt;h3 id="wiremock-instance-managed-by-the-test-framework"&gt;WireMock instance managed by the test framework&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s start with the easiest way to get WireMock running.&lt;/p&gt;
&lt;p&gt;JUnit can manage a WireMock instance. I will use the JUnit 5 WireMock extension that provides the &lt;code&gt;@WireMockTest&lt;/code&gt; annotation:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-java"&gt;@WireMockTest
public class HelloWireMockTest {

 @Test
 void hello_stub_test() {
 // Let's create a first stub
 stubFor(get(&amp;quot;/hello&amp;quot;).willReturn(ok()));

 // And test if the stub works using RestAssured
 given().baseUri(&amp;quot;http://localhost:8080&amp;quot;)
 .when().get(&amp;quot;/hello&amp;quot;)
 .then().assertThat().statusCode(200);
 }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For this test scenario, the test framework will start the WireMock instance and I don&amp;rsquo;t need to worry about creating one in the test or connecting to the standalone one.&lt;/p&gt;
&lt;p&gt;By default, the WireMock extension starts a WireMock instance on port 8080. You can change it by specifying the &lt;code&gt;httpPort&lt;/code&gt; parameter on the annotation, i.e.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-java"&gt;@WireMockTest(httpPort = 9999)
public class HelloWireMockTest {}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you are still using JUnit 4, see how to do the same for that version of the test framework: &lt;a href="https://wiremock.org/docs/junit-extensions/"&gt;WireMock Docs » JUnit 4 and Vintage&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="starting-instance-programmatically"&gt;Starting instance programmatically&lt;/h3&gt;
&lt;p&gt;If my test framework is not JUnit but is JVM-based, I can start a WireMock instance programmatically:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-java"&gt;public class ExamplePlainJavaTest {

 private static WireMockServer server;

 @BeforeAll
 public static void setup() {
 // Start WireMock instance
 server = new WireMockServer(options().port(9999));
 server.start();
 // Configure WireMock client to use port 9999
 WireMock.configureFor(9999);
 }

 @AfterAll
 public static void teardown() {
 server.stop();
 }

 @Test
 public void wiremock_example() {
 stubFor(get(&amp;quot;/hello&amp;quot;).willReturn(ok()));
 }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the &lt;code&gt;setup()&lt;/code&gt; method I am starting a WireMock instance on port 9999. Then I need to configure the WireMock client to the proper port to be able to use the API the same way as in the previous example.&lt;/p&gt;
&lt;p&gt;After the tests are finished, I need to remember to stop the WireMock instance in the &lt;code&gt;teardown()&lt;/code&gt; method.&lt;/p&gt;
&lt;h3 id="wiremock-standalone-instance"&gt;WireMock standalone instance&lt;/h3&gt;
&lt;p&gt;Usually for my testing I use WireMock in standalone mode with a Docker container.&lt;/p&gt;
&lt;p&gt;To start a Docker image use the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;docker run -it --rm \
 -p 8080:8080 \
 --name wiremock \
 wiremock/wiremock:3.13.2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Alternatively, you can download the JAR file using the link provided in &lt;a href="https://wiremock.org/docs/download-and-installation/#direct-download"&gt;WireMock Docs » Direct Download&lt;/a&gt; and start it with:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;java -jar wiremock-standalone-3.13.2.jar
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this case you can use the WireMock API directly without any prior configuration, as the default 8080 port is used.&lt;/p&gt;
&lt;p&gt;In both cases, it is worth adding the &lt;code&gt;--verbose&lt;/code&gt; option to the command to be able to inspect the requests and responses that WireMock handles during the test.&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;WireMock is a practical tool for simulating external HTTP APIs, especially when the real service is unstable, rate-limited, or not yet available. This article showed how to add WireMock as a test dependency, run it under JUnit 5, start it programmatically from JVM code, and use it as a standalone service in Docker or via the JAR.&lt;/p&gt;
&lt;p&gt;In the next articles I will show how to construct more robust stubs, test error scenarios and use more advanced features of WireMock.&lt;/p&gt;</description></item><item><title>REST API Testing with ScalaTest - Matchers</title><link>https://hiquality.dev/posts/rest-api-testing-with-scalatest-matchers/</link><pubDate>Tue, 02 Apr 2024 21:00:00 +0200</pubDate><guid>https://hiquality.dev/posts/rest-api-testing-with-scalatest-matchers/</guid><summary>&lt;p&gt;In the &lt;a href="https://hiquality.dev/posts/automated-acceptance-tests-with-scalatest/"&gt;previous post&lt;/a&gt;
I&amp;rsquo;ve described how to start with test automation of the REST API using ScalaTest.
Today I would like to show some more examples of using ScalaTest matchers - a smart
way of writing more readable assertions.&lt;/p&gt;
&lt;h2 id="string-matchers"&gt;String matchers&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s get back for a while to our
&lt;a href="https://hiquality.dev/posts/automated-acceptance-tests-with-scalatest/#example-send-request"&gt;previous code example&lt;/a&gt;.
Our test seems still a bit unfinished as we have no assertions on the response body.
ScalaTest has few methods defined called matchers which will give us nice looking assertions
on the different data types.&lt;/p&gt;</summary><description>&lt;p&gt;In the &lt;a href="https://hiquality.dev/posts/automated-acceptance-tests-with-scalatest/"&gt;previous post&lt;/a&gt;
I&amp;rsquo;ve described how to start with test automation of the REST API using ScalaTest.
Today I would like to show some more examples of using ScalaTest matchers - a smart
way of writing more readable assertions.&lt;/p&gt;
&lt;h2 id="string-matchers"&gt;String matchers&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s get back for a while to our
&lt;a href="https://hiquality.dev/posts/automated-acceptance-tests-with-scalatest/#example-send-request"&gt;previous code example&lt;/a&gt;.
Our test seems still a bit unfinished as we have no assertions on the response body.
ScalaTest has few methods defined called matchers which will give us nice looking assertions
on the different data types.&lt;/p&gt;
&lt;h3 id="startwith-endwith-include"&gt;startWith, endWith, include&lt;/h3&gt;
&lt;p&gt;First, we&amp;rsquo;ll check simple assertions working on Strings:&lt;/p&gt;
&lt;p&gt;The response body must contain the blog name:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;response.body must include(&amp;quot;https://hiquality.dev&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The body must also start and end with braces:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;response.body must startWith(&amp;quot;{&amp;quot;)
response.body must endWith(&amp;quot;}&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="regular-expressions"&gt;Regular expressions&lt;/h3&gt;
&lt;p&gt;We can also check if the response body matches a regular expression:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;response.body must fullyMatch regex &amp;quot;&amp;quot;&amp;quot;.*&amp;quot;blog&amp;quot;:&amp;quot;(https://)?hiquality\.dev&amp;quot;.*&amp;quot;&amp;quot;&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="parsing-a-response-to-json"&gt;Parsing a response to JSON&lt;/h2&gt;
&lt;p&gt;Checking the response body as string might be a bit too verbose.
Of course there is a better way to do it: we&amp;rsquo;ll parse the response body to a Scala object.&lt;/p&gt;
&lt;p&gt;In this example I&amp;rsquo;ve chosen &lt;a href="%22https://circe.github.io/circe/%22"&gt;Circe&lt;/a&gt; -
one of the most popular JSON libraries for Scala.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s add some dependencies to &lt;code&gt;build.sbt&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;val circeVersion = &amp;quot;0.14.6&amp;quot;
libraryDependencies += &amp;quot;io.circe&amp;quot; %% &amp;quot;circe-core&amp;quot; % circeVersion
libraryDependencies += &amp;quot;io.circe&amp;quot; %% &amp;quot;circe-generic&amp;quot; % circeVersion
libraryDependencies += &amp;quot;io.circe&amp;quot; %% &amp;quot;circe-parser&amp;quot; % circeVersion
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&amp;rsquo;ll use also sttp&amp;rsquo;s Circe integration:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;libraryDependencies += &amp;quot;com.softwaremill.sttp.client3&amp;quot; %% &amp;quot;circe&amp;quot; % &amp;quot;3.9.3&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First we&amp;rsquo;ll define a &lt;code&gt;GitHubUserProfile&lt;/code&gt; case class:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;case class GitHubUserProfile(
 login: String,
 id: Int,
 name: String,
 company: Option[String],
 blog: String
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and pass it as a type parameter to the decoder in the request definition:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;val request = quickRequest
 .get(uri&amp;quot;https://api.github.com/users/kkomorowski&amp;quot;)
 .response(asJson[GitHubUserProfile])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the previous example the response body had type &lt;code&gt;String&lt;/code&gt;.
This time it is different and - the client returns
&lt;code&gt;Either[ResponseException[String, circe.Error], GitHubUserProfile]&lt;/code&gt;.
If parsing the response body fails, we&amp;rsquo;ll get an exception on the
left side of the &lt;code&gt;Either&lt;/code&gt;, otherwise we&amp;rsquo;ll get the parsed object on the right side.&lt;/p&gt;
&lt;p&gt;We can now check if the response was successful and safely extract the value from the &lt;code&gt;Either&lt;/code&gt;
and assert on the fields of the object:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;response.body.isRight must be(true)
val user = response.body.toOption.get
user.blog must be(&amp;quot;https://hiquality.dev&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem with this code snippet is when the first assertion fails, we&amp;rsquo;ll get quite
unpleasant error on the logs:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-text"&gt;false was not equal to true
ScalaTestFailureLocation: GitHubUserSpec at (GitHubUserSpec.scala:49)
Expected :true
Actual :false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Except for the file and line number in the stack trace this gives not much
clue what was the reason for failure. If we skip the assertion here, we could
end up in even more cumbersome &lt;code&gt;NoSuchElementException&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="eithervalues-trait"&gt;EitherValues trait&lt;/h2&gt;
&lt;p&gt;Fortunately ScalaTest provides a handy &lt;code&gt;EitherValues&lt;/code&gt; trait that makes
it easier to work with &lt;code&gt;Either&lt;/code&gt; values.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s import it and use it in our test:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;import org.scalatest.EitherValues
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and mix-in it by extending our test class.&lt;/p&gt;
&lt;p&gt;We can now write our previous assertion the following way:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;val user = response.body.value
user.blog must be(&amp;quot;https://hiquality.dev&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;value&lt;/code&gt; implicit conversion is used to extract the value
from the &lt;code&gt;Either&lt;/code&gt; and to assert on it.&lt;/p&gt;
&lt;p&gt;We can also assert on the left side of the &lt;code&gt;Either&lt;/code&gt; if the parsing of the response body fails:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;response.body.left.value mustBe a [ResponseException[_, _]]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the example above we&amp;rsquo;ve asserted not on the value but on the type of the left side of the &lt;code&gt;Either&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Similar traits as &lt;code&gt;EitherValues&lt;/code&gt; exist for &lt;code&gt;Option&lt;/code&gt; and &lt;code&gt;Try&lt;/code&gt; types.&lt;/p&gt;
&lt;h2 id="matcher-negations"&gt;Matcher negations&lt;/h2&gt;
&lt;p&gt;We can also easily negate the matcher by using a &lt;code&gt;not&lt;/code&gt; word in our matcher.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;user.blog must not be empty
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In this blog post we&amp;rsquo;ve learned how to parse an HTTP response body to
Scala case class using Circe. We&amp;rsquo;ve tried different ways of writing
the assertions in the test and have more readable error messages
for the failed assertions thanks to &lt;code&gt;EitherValue&lt;/code&gt; trait provided by
ScalaTest.&lt;/p&gt;
&lt;p&gt;Thanks for reading this article and see you in the next episode
of ScalaTest series.&lt;/p&gt;</description></item><item><title>Automated Acceptance Tests with ScalaTest</title><link>https://hiquality.dev/posts/automated-acceptance-tests-with-scalatest/</link><pubDate>Tue, 20 Feb 2024 19:45:00 +0100</pubDate><guid>https://hiquality.dev/posts/automated-acceptance-tests-with-scalatest/</guid><summary>&lt;p&gt;Almost seven years ago I&amp;rsquo;ve started a new and unexpected journey. Back then
I had some experience with test automation in Python and Java and I&amp;rsquo;ve joined
the team working on the backend application written in Scala. It was my first
experience with functional programming so I was wondering if
it would not be hard to learn and maintain the test suite written in this
new for me language. It turned out that it&amp;rsquo;s not and the work with Scala
gave me a lot of fun.&lt;/p&gt;
&lt;p&gt;In this first episode of the blog post series I would like to show how
to start testing a REST API using ScalaTest and how to use some more
advanced features of this one of the most popular Scala-based test frameworks.&lt;/p&gt;</summary><description>&lt;p&gt;Almost seven years ago I&amp;rsquo;ve started a new and unexpected journey. Back then
I had some experience with test automation in Python and Java and I&amp;rsquo;ve joined
the team working on the backend application written in Scala. It was my first
experience with functional programming so I was wondering if
it would not be hard to learn and maintain the test suite written in this
new for me language. It turned out that it&amp;rsquo;s not and the work with Scala
gave me a lot of fun.&lt;/p&gt;
&lt;p&gt;In this first episode of the blog post series I would like to show how
to start testing a REST API using ScalaTest and how to use some more
advanced features of this one of the most popular Scala-based test frameworks.&lt;/p&gt;
&lt;h2 id="setting-up-scalatest-test-project"&gt;Setting up ScalaTest test project.&lt;/h2&gt;
&lt;p&gt;Scala is a JVM based language so we will need to have JDK installed (I usually use
the latest LTS release &amp;ndash; 21 at the time of writing this article).&lt;/p&gt;
&lt;p&gt;We would also use &lt;a href="https://www.scala-sbt.org/"&gt;SBT&lt;/a&gt; &amp;ndash; the most popular build tools
for Scala projects.&lt;/p&gt;
&lt;p&gt;After installing both we can start a new ScalaTest project from scratch
using following in your command line:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;sbt new scala/scalatest-example.g8&lt;/code&gt; &lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;You can also clone the GitHub repository with the code presented
in this article: &lt;a href="https://github.com/kkomorowski/scalatest-getting-started"&gt;https://github.com/kkomorowski/scalatest-getting-started&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="some-gherkin-please"&gt;Some Gherkin, please!&lt;/h2&gt;
&lt;p&gt;The clue of the Behavior-Driven Development are the well defined test
scenarios that might be used as the documentation of the system. ScalaTest
is a very versatile test framework that gives the possibility of
choosing the test style that best suites your needs.&lt;/p&gt;
&lt;p&gt;In the example we&amp;rsquo;ll use &lt;code&gt;FeatureSpec&lt;/code&gt; and &lt;code&gt;GivenWhenThen&lt;/code&gt; from ScalaTest
to describe the scenarios of our tested feature using Gherkin-like DSL:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;class GitHubUserSpec extends AnyFeatureSpec with GivenWhenThen:

 Feature(&amp;quot;GitHub User Profile&amp;quot;):

 info(&amp;quot;As a programmer&amp;quot;)
 info(&amp;quot;I want to check the user profile presence&amp;quot;)
 info(&amp;quot;So I know if I can create an account with a given name&amp;quot;)

 Scenario(&amp;quot;GitHub User Exists&amp;quot;):
 Given(&amp;quot;a GitHub account exists&amp;quot;)
 When(&amp;quot;I send a request to the /user/{username} API endpoint&amp;quot;)
 Then(&amp;quot;I get the response with HTTP status code 200&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;NOTE: The examples use the Scala 3
&lt;a href="https://docs.scala-lang.org/scala3/reference/other-new-features/indentation.html"&gt;significant indentation&lt;/a&gt;.
This way of writing of ScalaTest scenarios even more resembles Cucumber &lt;code&gt;feature&lt;/code&gt; files to me.&lt;/p&gt;
&lt;h2 id="lets-make-a-request"&gt;Let&amp;rsquo;s make a request!&lt;/h2&gt;
&lt;p&gt;Unlike Cucumber or JBehave our &lt;code&gt;Given When Then&lt;/code&gt; steps are purely informational
and does not bring any implementation of the test behind. We need to implement
the test code ourself.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s try to make a first request. Scala is highly compatible with Java
so we could use one of the well known API testing libraries like RestAssured but here I would like to
show you &lt;a href="https://sttp.softwaremill.com/en/stable/"&gt;sttp&lt;/a&gt; &amp;ndash; a Scala-based library that
will send the HTTP request for us.&lt;/p&gt;
&lt;p&gt;Simply add this line to your &lt;code&gt;build.sbt&lt;/code&gt; project file:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;libraryDependencies += &amp;quot;com.softwaremill.sttp.client3&amp;quot; %% &amp;quot;core&amp;quot; % &amp;quot;3.9.3&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and import to easily use Java HTTP client from Scala code:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;import sttp.client3.quick.*
&lt;/code&gt;&lt;/pre&gt;
&lt;p id="example-send-request"&gt;Now we can fill up our scenario with the code:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt;Scenario(&amp;quot;GitHub User Exists&amp;quot;):
 Given(&amp;quot;a GitHub account exists&amp;quot;)
 val username = &amp;quot;kkomorowski&amp;quot;
 When(&amp;quot;I send a request to the /user/{username} API endpoint&amp;quot;)
 val request = quickRequest.get(uri&amp;quot;https://api.github.com/users/$username&amp;quot;)
 val response = simpleHttpClient.send(request)
 Then(&amp;quot;I get the response with HTTP status code 200&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="-and-assert-on-the-response"&gt;&amp;hellip; and assert on the response.&lt;/h2&gt;
&lt;p&gt;The only thing left is to assert on the response from the API.
We can use ScalaTest matchers to have the code more readable:&lt;/p&gt;
&lt;p&gt;Add &lt;code&gt;org.scalatest.matchers.must.Matchers&lt;/code&gt; to the imports and extend your
test class with &lt;code&gt;Matchers&lt;/code&gt; trait. Now we can write the assertion
the following way:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-scala"&gt; response.code mustBe StatusCode(200)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="running-your-first-tests"&gt;Running your first tests&lt;/h2&gt;
&lt;p&gt;The test is ready to be run. You can run it easily from the IDE (IntelliJ IDEA
is able to do it when equipped with Scala plugin. VSCode needs Metals extension).&lt;/p&gt;
&lt;p&gt;To run the tests from the command line we can use &lt;code&gt;sbt&lt;/code&gt;, just write:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sbt test
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in your command line.&lt;/p&gt;
&lt;p&gt;After few lines of the logs from the build stage you should see a simple
text base test report similar to this one:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-markdown"&gt;[info] GitHubUserSpec:
[info] Feature: GitHub User Profile
[info] As a programmer 
[info] I want to check the user profile presence 
[info] So I know if I can create an account with a given name 
[info] Scenario: GitHub User Exists
[info] Given a GitHub account exists 
[info] When I send a request to the /user/{username} API endpoint 
[info] Then I get the response with HTTP status code 200
[info] Run completed in 1 second, 811 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="end-words"&gt;End words&lt;/h2&gt;
&lt;p&gt;In this article we&amp;rsquo;ve written our acceptance tests of the REST API using ScalaTest.
Using &lt;code&gt;FeatureSpec&lt;/code&gt; and &lt;code&gt;GivenWhenThen&lt;/code&gt; trait we&amp;rsquo;ve been able describe
the test scenarios and add the logic code of the test using STTP library
to make the HTTP request and add a simple assertion on the result.&lt;/p&gt;
&lt;p&gt;I hope that this short guide gave you an inspiration to try ScalaTest
in your testing project and convinced you that it might not be that
hard to learn.&lt;/p&gt;
&lt;div class="footnotes" role="doc-endnotes"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;You can find an official guide on the Scala Language website:
&lt;a href="https://docs.scala-lang.org/getting-started/sbt-track/testing-scala-with-sbt-on-the-command-line.html"&gt;https://docs.scala-lang.org/getting-started/sbt-track/testing-scala-with-sbt-on-the-command-line.html&lt;/a&gt;.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description></item><item><title>About Me</title><link>https://hiquality.dev/about/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://hiquality.dev/about/</guid><summary>&lt;div id="homepost"&gt;
&lt;img id="authors_pic" src="https://hiquality.dev/profile.jpg"/&gt;
&lt;div&gt;
&lt;h1 id="hi"&gt;Hi!&lt;/h1&gt;
&lt;p&gt;Welcome to my blog. My name is &lt;strong&gt;Krzysztof Komorowski&lt;/strong&gt;.
I am test engineer and software developer pasionate
about functional programming.&lt;/p&gt;
&lt;p&gt;You can find me at:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mastodon.social/@kkomorowski"&gt;Mastodon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/kkomorowski"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/krzysztof-komorowski-4194155"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;/div&gt;</summary><description>&lt;div id="homepost"&gt;
&lt;img id="authors_pic" src="https://hiquality.dev/profile.jpg"/&gt;
&lt;div&gt;
&lt;h1 id="hi"&gt;Hi!&lt;/h1&gt;
&lt;p&gt;Welcome to my blog. My name is &lt;strong&gt;Krzysztof Komorowski&lt;/strong&gt;.
I am test engineer and software developer pasionate
about functional programming.&lt;/p&gt;
&lt;p&gt;You can find me at:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mastodon.social/@kkomorowski"&gt;Mastodon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/kkomorowski"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/krzysztof-komorowski-4194155"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;/div&gt;</description></item></channel></rss>