Testing RESTful Service in Ruby, Part 2: Run frequently in a Continuous Testing Server

Stabilizing the tests and setting them up in a Continuous Testing server

Zhimin Zhan
7 min readAug 1, 2022

--

In Part 1, I created five RESTful service tests in Ruby. They were working, however, but the task is not completed yet.

Table of Contents:
· Stabilize Tests:
1. LIST all records
2. READ one record
3. CREATE a new record
4. UPDATE a new record
5. DELETE a record
· Run all tests in TestWise a couple of times
· Set up build project in BuildWise to run all tests in a CT Server
· Review (by Zhimin)
Effort on Test Creation is minor
The Power of Scripting in Ruby
Universally Applicable
Freedom and Fun
The Synergy

I hardcoded an ID value (e.g. 66670) to use in some tests, which run fine once only. The ID might already be taken (duplicate error for CREATE), or may not exist (causing READ, UPDATE and DELETE operations to fail). Also, I didn’t clean up after using it.

To run tests in a Continuous Testing (CT) server, I should stabilize the tests firsts: can run them successfully multiple times. In this article, I will revise the tests written in Part 1 and set up running them in a CT server, as regression testing.

Stabilize Tests:

1. LIST all records

No changes from Part 1.

  it "List all records" do
require "httpclient"
require "rexml"
http = HTTPClient.new
resp = http.get("http://www.thomas-bayer.com/sqlrest/CUSTOMER")
xml_doc = REXML::Document.new(resp.body)
expect(xml_doc.root.elements.size).to be > 10
expect(xml_doc.root.elements.first.text).to eq("1")
end

2. READ one record

No changes, maybe. It might be OK to assume that record #1 always exists, so long as there are no attempts to update or delete it. If this test starts to fail, we can always stabilize this by invoking CREATE service to use the freshly created one (see UPDATE or DELETE for more).

it "Read first record" do
http = HTTPClient.new
customer_id = 1
get_rest_url = "http://www.thomas-bayer.com/sqlrest/CUSTOMER/#{customer_id}"
resp =…

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.

Recommended from Medium

Lists

See more recommendations