7.2.1 Testing 7.2.1 测试
When we are programming, errors will happen, and we have to learn to deal with them. Testing is the process of examining a program to see if any errors might be present. This is a different process from debugging, which where we look for the source of errors once we've determined they exist.
当我们编程时,会发生错误,我们必须学会处理它们。测试是检查程序以查看是否存在任何错误的过程。这是一个与调试不同的过程,在调试中,我们在确定错误存在后查找错误源。
Testing in software development is an important and often independent area of work. Most large organisations carry out testing using teams of people who were not involved in the initial development of the software. This is done mainly to ensure that no biases creep into the testing process. The main reasons for testing are to ensure a program produces the correct functionality and identify any bugs that could cause the program to crash or behave unexpectedly.
软件开发中的测试是一个重要且通常独立的工作领域。大多数大型组织使用未参与软件初始开发的人员团队进行测试。这样做主要是为了确保测试过程中没有偏见。进行测试的主要原因是确保程序产生正确的功能,并识别可能导致程序崩溃或意外行为的任何错误。
Definition: Testing is the activity of finding out whether a piece of code (a method, class, or program) produces the intended behaviour.
定义:测试是找出一段代码(方法、类或程序)是否产生预期行为的活动。
We must keep in mind that writing logically correct programs is a difficult task and for a large program it is never possible to be certain that they are free of bugs. Most commercial software systems are known to contain significant numbers of bugs.
我们必须记住,编写逻辑正确的程序是一项艰巨的任务,对于大型程序来说,永远不可能确定它们没有错误。已知大多数商业软件系统都包含大量错误。
When it comes to software testing there are two main approaches that are adopted. The first is the manual approach, where the programmer or tester steps through the code step-by-step to ensure compliance. The second approach is automation, where test scripts are written and run against the code to check for compliance. The test scripts are typically automated using a test automation tool. The goal of test automation is to increase the effectiveness and efficiency of testing.
在软件测试方面,主要采用两种方法。第一种是手动方法,程序员或测试人员逐步完成代码以确保合规性。第二种方法是自动化,其中针对代码编写和运行测试脚本以检查合规性。测试脚本通常使用测试自动化工具实现自动化。测试自动化的目标是提高测试的有效性和效率。
Both approaches have merits and limitations, and the more obvious time and cost implications. Large organisations strive for a balance between both approaches to testing wherein small aspects such as unit testing are automated but larger aspects are not.
这两种方法都有优点和局限性,以及更明显的时间和成本影响。大型组织力求在两种测试方法之间取得平衡,其中小方面(如单元测试)是自动化的,但较大的方面不是。
The following are some of the main types of software testing:
以下是软件测试的一些主要类型:
Functional testing 功能测试
This involves testing the functional components of the software being developed. This type of testing seeks to establish whether each aspect of the application works as per the specification. Below we discuss a few types of functional testing, not in any particular order.
这涉及测试正在开发的软件的功能组件。这种类型的测试旨在确定应用程序的每个方面是否按照规范工作。下面我们讨论几种类型的功能测试,不按任何特定顺序。Unit testing 单元测试
These are low level tests where the smallest testable components of an application are tested individually and independently for their functionality correctness. A component could be a package, class, or method. The tests are conducted during the development process by the software developers.
这些是低级测试,其中应用程序的最小可测试组件单独且独立地测试其功能正确性。组件可以是包、类或方法。测试由软件开发人员在开发过程中进行。
Integration testing 集成测试
Integration testing is the next step once unit testing has been completed. In this testing, different units, modules or components of a system are tested as a combined entity to ensure they can function together.
集成测试是单元测试完成后的下一步。在此测试中,系统的不同单元、模块或组件作为组合实体进行测试,以确保它们能够一起运行。
System testing 系统测试
System testing ensures that the overall system performs the required tasks and works as expected. For very large and complex systems this could involve testing the integration of all the components as a whole system to ensure no errors or issues exist.
系统测试可确保整个系统执行所需的任务并按预期工作。对于非常大和复杂的系统,这可能涉及测试所有组件作为一个整体系统的集成,以确保不存在错误或问题。
Interface testing
Involves the testing of all interfaces within the program. This doesn't necessarily mean just the front-end of the software, interface testing can also include other interfaces within the program which are used to communicate between different components, such as API's and web services.Regression testing
Regression testing is done when a software has been extended to add new functionality or when the initial or subsequent builds of the program did not pass the required testing. The purpose of regression testing is to ensure that all unaffected or unmodified parts of the program are still error free after some modifications have been made to other parts of the program.Beta/acceptance testing
This is done to ensure that the software meets the requirements of the client, and it is acceptable for delivery.
Non-functional testing
This type of testing involves testing the operational aspects of the software being developed. It generally focuses on the various aspects such as performance, reliability and usability. While there are many branches of non-functional testing, we will not explore these further in this unit.
Testing is a large topic, and we will only give an introduction to testing in this unit. However, it is important for new programmers to understand at least the basic levels of testing to ensure that their programs are relatively error free.
For this unit, we will focus on unit testing and learn how we can apply it to our programming.