Sitemap
Swe Swe Mar Soe

Swe Swe Mar Soe

A rubyist girl who loves codes | photography | digital arts| animes | http://swesweucsy.github.io/en/portfolios

Testing in Ruby

2 min readJan 18, 2018

Initially, I would like to share about testing in Ruby.
First, I will suppose we have already known about ruby and
have already installed ruby environments.

Now, We will create a Calculator class. This class will be simple:

And, now We will add about test class. Initially we’ll put test class under same directory.

Our test class will look like this:

And, we’ll run test code from terminal shell.

ruby -I . test_add.rb

Of course, test fails. Result will look like this:

Press enter or click to view image in full size
arugument_error

Now We’ll fix at our calculator class.

Press enter or click to view image in full size

And, we’ll run test code again( note: Our calculator doesn’t anything yet). It will shows like that:

Press enter or click to view image in full size

We’ll fix calculator code again and will test again:

Press enter or click to view image in full size
fix error 2
Press enter or click to view image in full size
success test-case

Note that: you’ll see a simple ‘.’ in the outputs of test result.
a ‘.’ intends for each test that passes meaning we can scan quickly.

Get Swe Swe Mar Soe’s stories in your inbox

Join Medium for free to get updates from this writer.

Now, we’ll add second test code.

Press enter or click to view image in full size
test_add.rb( include second test-case)

Second test will run again:

Press enter or click to view image in full size
success test-cases( include two test-cases )

Now, you will see “..” in results. A “..” means two tasks.

That’s all. I hope my topic makes you be helpful.

I would appreciate hearings about your thoughts and opinion on my story. Thank you all reading.

source link: https://github.com/swesweucsy/unit_test_ruby

--

--

Swe Swe Mar Soe
Swe Swe Mar Soe

Written by Swe Swe Mar Soe

A rubyist girl who loves codes | photography | digital arts| animes | http://swesweucsy.github.io/en/portfolios