Automatic code testing

Is it a good developer? Ask him to comment something and you’ll find out!

Антон Андрющенко
Eulerr
6 min readDec 3, 2017

--

Before we start

Testing allows you to make the code more reliable, your life — easier. Besides, this process can be executed by computer. It is called automated testing. It uses software tools to do tests and check the results of execution. It helps to reduce testing time and simplify process. Test automated testing is especially useful when developing large projects in a big team, because you can accidentally break down some function, that another person wrote, and you did not know about. Also, you should use it when you need to finish the previously written complex project. In fact, large project development is almost impossible without automated testing.

A review of different approaches to testing

What to test? Program can be tested in different levels: Code (unit-tests and integrational testing), API and GUI. The choice of the type of test depends on situation.

Code testing

The code testing may be complete on different levels:

  • Unit testing is a software testing method that allows you to check the correctness of units of source code, sets of one or more computer program modules together with associated control data, usage procedures and operating procedures.
    This means that if the code uses some third-party classes, then stub classes are put instead of them. The code should not work with the network and external servers, files, database (otherwise we do not test only the function or class, and also a disk, a base, etc.).
    The idea is to write tests for each non-trivial function or method. This allows you to quickly check whether the next change in the code led to regression (to the appearance of errors in the already tested locations of the program), and also facilitates the detection and elimination of such errors.
  • Integration testing is the phase in software testing in which individual software modules (classes or functions) are combined and tested as a group. It has to be done in controlled environment in order to avoid mistakes and achieve independence from external conditions.

API testing

API (Application Programming Interface) — a set of ready-made classes, procedures, functions, structures and constants provided by the application (library, service) for using in external software products. If the application has an API, then you can test it by sending pre-prepared queries and comparing the incoming response with the expected one.

GUI testing

The most popular form of automation is testing applications through the graphical user interface (GUI). The popularity of this type of testing is explained by two factors: first, the application is tested in the same way that it will be used by the person; secondly, you can test the application without having access to the source code. GUI tests are also called End-to-End (E2E) or acceptance tests. Usually, the GUI is tested with usage of scenarios that describe the sequence of actions and check the expected result.

Load testing

Load testing is the process of putting demand on a software system or computing device and measuring its response. Load testing is performed to determine a system’s behavior under both normal and anticipated peak load conditions. It helps to identify the maximum operating capacity of an application as well as any bottlenecks and determine which element is causing degradation.

Tools

  • PVS-Studio is a tool for detecting errors in the source code of programs written in C, C ++ and C #. Works in Windows and Linux. PVS-Studio performs static code analysis and generates a report that helps the programmer find and fix errors. PVS-Studio performs a wide range of code checks, but its strongest skill is the search for typos and the consequences of an unsuccessful Copy-Paste. The main value of static analysis lies in its regular use, due to which many errors can be identified and eliminated at the earliest stages.
  • Codacy is an automated code analysis / quality tool that helps developers ship faster software, faster. With Codacy, you get static analysis, cyclomatic complexity, duplication and code unit. You can use Codacy to enforce your code quality standards, enforce security best practices and onboard developers faster. It allows you to integrate with your GitHub repositories to get quality analysis of every pull request inside GitHub.
  • Stickler CI is a software as a service application that automates the more tedious parts of code review; enforcing style and checking lint errors. It integrates with your GitHub repositories and checks each pull request for code style errors. Stickler CI will leave review comments when someone on your team makes a style error. This saves developer time as feedback on style errors is handled automatically, and your team doesn’t have to read through build reports to find whitespace errors.
  • _pullRequest provides a wide range of possibilities: from static analysis to an on-demand network of code review experts.
  • JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development
  • NUnit is an open source unit testing framework for Microsoft .NET
  • Selenium is a portable software-testing framework for web applications. Selenium provides a playback (formerly also recording) tool for authoring tests without the need to learn a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including C#, Groovy, Java, Perl, PHP, Python, Ruby and Scala. The tests can then run against most modern web browsers. Selenium deploys on Windows, Linux, and macOS platforms. It is open-source software, released under the Apache 2.0 license: web developers can download and use it without charge.

Problems

One of the main problems of automated testing is labor intensity: despite the fact that it can reduce the number of routine operations and speed up the execution of tests, updating tests may require large resources. This applies to both types of automation. When refactoring, it is often necessary to update unit tests, but changing the test code can take as much time as changing the main code. Nevertheless, when changing the application interface, you need to rewrite all the tests associated with the updated windows, which may require significant resources if you have a large number of tests.

And remember…

The more testing events will be completed the more profitable and stable will be your product!

Oftenly, you may find a good testing specialist in a huge development team, but not working with freelancers!

--

--