Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be stated as the process of validating and verifying that a software program or application or product: Meets the business and technical requirements that guided its design and development.
What are software tests?
A software test is a piece of software, which executes another piece of software. It validates if that code results in the expected state (state testing) or executes the expected sequence of events (behavior testing).
Software unit tests help the developer to verify that the logic of a piece of the program is correct.
Running tests automatically helps to identify software regressions introduced by changes in the source code. Having high test coverage of code allows us to continue developing features without having to perform lots of manual tests.
Testing terminology
1. Code (or application) under test
The code which is tested is typically called the code under test. If we are testing an application, this is called the application under test.
2. Test fixture
A test fixture is a fixed state in code which is tested used as input for a test. Another way to describe this is a test precondition.
For example, a test fixture might be a fixed string, which is used as input for a method. The test would validate if the method behaves correctly with this input.
3. Unit tests and unit testing
A unit test is a piece of code written by a developer that executes a specific functionality in the code to be tested and asserts a certain behavior or state.
The percentage of code which is tested by unit tests is typically called test coverage.
A unit test targets a small unit of code, e.g., a method or a class. External dependencies should be removed from unit tests, e.g., by replacing the dependency with a test implementation or a (mock) object created by a test framework.
Unit tests are not suitable for testing complex user interface or component interaction. For this, we should develop integration tests.
4. Integration tests
An integration test aims to test the behavior of a component or the integration between a set of components. The term functional test is sometimes used as synonym for integration test. Integration tests check that the whole system works as intended; therefore they are reducing the need for intensive manual tests.
These kinds of tests allow you to translate user stories into a test suite. The test would resemble an expected user interaction with the application.
5. Behavior vs. state testing
A test is a behavior test (also called interaction test) if it checks if certain methods were called with the correct input parameters. A behavior test does not validate the result of a method call.
State testing is about validating the result. Behavior testing is about testing the behavior of the application under test.
While testing algorithms or system functionality, in most cases you may want to test state and not interactions. A typical test setup uses mocks or stubs of related classes to abstract the interactions with these other classes away afterwards you test the state or the behavior depending on your need.
6. Performance tests
Performance tests are used to benchmark software components repeatedly. Their purpose is to ensure that the code under test runs fast enough even if it’s under high load.
Testing frameworks for Java
There are several testing frameworks available for Java. The most popular ones are JUnit and TestNG
Where should the test be located?
Typical, unit tests are created in a separate project or separate source folder to keep the test code separate from the real code. The standard convention from the Maven and Gradle build tools is to use:
src/main/java - for Java classes
src/test/java - for test classes
Which part of the software should be tested?
It is a highly controversial topic as some developers believe every statement in code should be tested.
In any case, we should write software tests for the critical and complex parts of application. If we introduce new features a solid test suite also protects us against regression in existing code.
In general, it is safe to ignore trivial code (useless to write tests for getter and setter methods). Writing tests for these statements is time consuming and pointless, as you would be testing the Java virtual machine. The JVM itself already has test cases for this. If you are developing end user applications you are safe to assume that a field assignment works in Java.
If we start developing tests for an existing code base without any tests, it is good practice to start writing tests for code in which most of the errors happened in the past. This way we can focus on the critical parts of our application.
No comments:
Post a Comment