DEV Community

Deborah Bello for Our Time For Tech

Posted on • Updated on

The World Of Testing

As much as I wasn’t the one in the team that started working actively and researching on the issue created that would have to do with Testing later on, it was still definitely important that every one of us on the team knew what testing is all about, as it is an important skill for a developer and we would split the test writing tasks among ourselves in few weeks to come.

Before my research on understanding the importance of Testing and the different approaches to it, The idea of creating Tests felt very intimidating a skill to learn. This was probably because I had no former experience in it and from hearsay’s, it seemed hard, and not a joyful thing to do. However, I decided to see it as a learning ground and stepping stone into the world of Testing.

What are Tests?

These are scripts that produce a consistent result and prove that an application does what it is expected to do. Tests are developed concurrently with the actual application.
Often what to include in functional Tests(controller testing) are Testing for things such as:

  • Knowing if the web request was successful?
  • Knowing if the user was redirected to the right page?
  • If the user was successfully authenticated?
  • If the correct object is stored in the response template?
  • If the appropriate message is displayed to the user in the view?

An important piece of advice I learned in the documentation is to include a test for everything which could break and that it is best practice to have at least one test for each of your validations, and at least one test for every method in your model.

Approaches to Testing/Testing in Rails
In learning on testing, I saw different approaches, which are:

Unit Testing

Broadly speaking, unit testing is a testing method where individual units of source code, program modules, usage procedures, and operating procedures are tested to determine if they are fit for use. They make sure that a section of an application, or a “unit”, is behaving as intended. Unit tests are used to test models.
Although it is possible in Rails to run all tests simultaneously, each unit test case is tested independently to isolate issues that may arise.

Unit testing finds problems early in the development cycle rather than later. It’s always better to find bugs earlier so that features that are added later in the cycle are using the correct parts. Additionally, unit testing forces developers to structure functions and objects in better ways, since poorly written code can be impossible to test.
Finally, unit testing provides living documentation of the system as it is developed. The description of the tests can give an outsider a basic understanding of the unit’s API and its features. The goal of unit testing is to isolate each part of the program and show that the individual parts are correct.

Model Specs/RSpecs

Model specs are similar to unit tests, in that they are used to test smaller parts of the system, such as classes or methods. Sometimes they interact with the database, too. They should be fast and handle edge cases for the system under test.

MiniTests

Minitest is a testing suite for Ruby. It provides a complete suite of testing facilities supporting test-driven development (TDD), behavior-driven development (BDD), mocking, and benchmarking. It’s small, fast, and it aims to make tests clean and readable.
Minitest is the default testing suite used with Rails, so no further setup is required to get it to work. Along with RSpec, it is one of the two most commonly used testing suites used in Ruby.

I initially thought we were going to make use of Unit Tests over Mini Tests. However, It was indeed a joy and not too great a surprise when Arit (one of our senior Engineers), told us we would be creating MiniTests in few weeks to come.
MiniTest can handle both TDD and BDD syntax and comes with a bunch of testing tools to make automation easy.
There are even several extensions to customize MiniTest to your needs plus I learned it is even fairly easy to port Unit Test to MiniTest. It does have to be installed via bundler and MiniTests are often used over Unit Tests because the syntax encourages human-readable tests!

Ultimately, this process of researching testing has been very helpful. I now find it quite exciting to know that in few weeks to come I would have more knowledge on this as Arit(one of our Senior Engineers) is working on creating a video that explains, How to create MiniTests in simpler terms and details for the Team. I know it won’t be too difficult once we get fully started.
Additionally, I am also starting to have a bit of understanding in seeing its importance to maintaining well-organized and clean code which would make the development of Our Shiftwork app more resilient to bad data.
I am looking forward to exploring more facets of testing soon!

Referencing:
https://guides.rubyonrails.org/testing.html
https://en.m.wikipedia.org/wiki/Unit_testing#
https://dev.to/milandhar/unit-testing-in-rails-4oke
https://www.tutorialspoint.com/ruby-on-rails-2.1/rails-unit-testing.htm

Top comments (1)

Collapse
 
aritdeveloper profile image
Arit Developer

Excellent summary of testing within a development environment. Bravo!