Testing and Test-First Programming

Testing levels

  • Unit testing 单元测试
    测试某一小部分代码的正确性,尤其是测试某个函数。
  • Integration testing 集成测试
    The combined execution of 2 or more classes, packages, components, subsystems that have been created by multiple programmers or programming teams.
  • System testing 系统测试
    测试一整个已经集成好的系统,看这个系统是否满足需求,即在最终的一个配置下运行软件。

Test vs Debug

Testing是为了发现是否存在错误
Debugging为了识别、定位已知错误的根源

White-box vs black-box testing

白盒测试是对程序内部代码进行的测试。
黑盒测试仅针对陈旭外部表现出的行为进行测试。
软件测试的困难所在:穷举、暴力测试是不现实的。

Test case

测试用例=输入+执行条件+期望结果
好的测试用例需要有一下属性:
Most likely to catch the wrong
Not repetitive and not redundant
The most effective in a group of similar test cases
Neither too simple nor too complicated

Test-First programming

测试优先的编程:在写程序代码之前先写测试用例。
不要把测试留到最后。
测试用例要根据方法的规约(specification)来写,同时,写测试用例也是理解、修正、完善规约的过程。
(规约本身也有可能是错误的——不正确、不完整。)
测试优先可以尽早的发现规约中的问题,避免浪费时间去做错误的事情。
越早发现错误就越容易去纠正错误。

Unit Testing

Unit testing focuses verification effort on the smallest unit of software design —— the software component or module.
单元测试需要考虑的东西:
接口,测试的输入和输出;数据的完整性;所有语句都要被执行到过;所有的边界都要测试到。
Test cases for the black-box testing are built around specification and requirements. 测试用例的编写必须符合规约。

Choosing Test Case by Partitioning

按照等价类划分设计测试用例
Equivalence partitioning is a testing method that divides the input domain of a program into classes of data from which test cases can be derived.
针对每个输入数据需要满足的约束条件,划分等价类。
此方法可以将有限的测试资源最大化利用。

Guidelines

如果限定了输入数据的范围,则按不同范围划分;
如果指明了特定的值,则将几个特定的值按内在联系划分;
如果输入数据是Y/N,将两个都测一遍。

Example1

BigInteger.multiply():
BigInteger × BigInteger -> BigInteger
input: (a, b),从正负的角度对二维空间进行等价类划分:
a and b are both positive
a and b are both negative
a is positive, and b is negative
a is negative, and b is positive

需要考虑的特殊情况:0
考虑输入的上限:面对很大的数是否仍然正确?
综合以上的所有,划分为49个等价类:

从每个正方形内任意选取一组(a, b)

Example 2

public static int max(int a, int b)
int × int -> int
按如下等价类:
a < b
a = b
a > b

Boundary Value Analysis

A greater number of errors occurs at the boundaries of the input domain rather than in the center.
0 is a boundary between positive numbers and negative numbers.
Maximum and minimum values of numeric types, like int and double.
Emptiness (the empty string, empty list, empty array) for collection types.
The first and last element of a collection.

边界值分析方法是对等价类划分方法的补充。

重新设计max()的规约:
Relationship between a and b:
a < b
a = b
a > b

Value of a:(so is b)
a = 0
a < 0
a > 0
a = minimum integer
a = maximum integer

White-box testing

Whitebox testing (also called glass box testing) means choosing test cases with knowledge of how the function is actually implemented.

For example, if the implementation selects different algorithms depending on the input, then you should partition according to those domains.
If the implementation keeps an internal cache that remembers the answers to previous inputs, then you should test repeated inputs.

Other things

Running all your tests after every change is called regression testing.
Unit testing strategy is a complementary document of ADT’s design.
Aligning with the idea of test-first programming, it is recommended to write down the testing strategy (such as partitioning and boundary) according to which you design your test cases.

### Protobuf for AARCH64-Linux Installation and Usage For the installation of Protocol Buffers (protobuf) on an `aarch64-linux` platform, one can follow a series of commands that ensure all necessary dependencies are installed correctly. The process involves installing development libraries specifically tailored to this architecture. #### Installing Dependencies To prepare the system for protobuf compilation or use, it is essential first to install required packages using package managers like `apt`. For systems based on Debian or Ubuntu derivatives targeting the ARM64 (`aarch64`) architecture: ```bash sudo apt-get update && sudo apt-get upgrade -y sudo apt-get install -y build-essential cmake git pkg-config zip g++ zlib1g-dev unzip python3 python3-pip wget curl libcurl4-gnutls-dev libssl-dev ``` This command installs basic tools needed for building software from source along with Python-related utilities which might be useful when working alongside protobuf applications[^1]. #### Obtaining and Building Protobuf Source Code Given that pre-built binaries may not always exist for every target environment such as `aarch64`, compiling directly from sources becomes necessary. Downloading the latest stable release tarball from GitHub releases page ensures compatibility while also providing access to any recent improvements made by contributors. After extracting the archive into a directory named after its version number—for example, `protobuf-all-x.x.x`—one proceeds inside said folder before executing configuration scripts provided within: ```bash cd /path/to/extracted/folder/ ./autogen.sh ./configure --host=aarch64-linux-gnu CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ make -j$(nproc) sudo make install ``` The above sequence configures the project according to cross-compilation requirements specified through options passed during invocation; here `/usr/bin/aarch64-linux-gnu-gcc` serves as an illustrative path pointing towards appropriate GCC toolchain executables capable of generating code suitable for execution upon devices featuring ARM Cortex-A processors running Linux operating systems[^2]. #### Verifying Installation Success Once completed successfully without errors encountered throughout previous steps, verification checks should confirm proper functioning post-installation via simple test cases utilizing compiled binaries residing under standard locations defined at compile-time unless overridden explicitly earlier. Testing protocol buffer compiler functionality could involve creating minimalistic `.proto` files describing message structures followed by invoking `protoc` utility against them so generated output matches expectations set forth in official documentation accompanying distribution archives downloaded initially. ```bash echo 'syntax = "proto3";message TestMessage { string content = 1;}' >test.proto protoc --version protoc --cpp_out=. ./test.proto ls ./*.pb.cc rm *.pb.* test.proto ``` These operations generate C++ stubs corresponding to messages declared previously then clean up artifacts afterward leaving no trace behind except confirmation logs printed out onto terminal consoles indicating successful completion status codes returned accordingly[^3]. #### Using Protobuf Compiler Effectively With everything now properly configured, developers have multiple ways they can leverage protobuf capabilities depending on specific needs ranging from serializing/deserializing data efficiently across network boundaries down to defining contract-first APIs adhering strictly typed schemas enforced consistently regardless of underlying programming languages chosen later stages implementing business logic atop these foundations laid out beforehand carefully considering performance implications associated closely related aspects involved simultaneously ensuring maintainability over extended periods maintenance cycles expected typically seen enterprise-grade solutions built today's interconnected world wide web infrastructure spanning diverse ecosystems connected together forming vast networks communicating seamlessly exchanging information securely reliably fast accurately cost-effectively scalable resilient robust fault-tolerant architectures supporting modern application development practices widely adopted industry standards open-source communities alike contributing positively overall progress humanity makes collectively advancing knowledge frontiers pushing boundaries further exploring uncharted territories discovering new possibilities emerging continuously horizon expands ever outwardly boundless potential awaits those willing embrace change adapt evolving landscapes transforming rapidly around us constantly shifting paradigms redefining what possible tomorrow promises beyond imagination limits constrained only by current understanding reality shaping future generations inherit legacy leave behind today actions taken shape tomorrows yet unseen written history books read centuries henceforth remembered fondly celebrated achievements milestones reached overcoming challenges faced head-on courageously pursued dreams realized aspirations fulfilled visions materialized concrete forms tangible results manifested physical realm experienced senses perceive consciously aware existence itself.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值