ALevel-CS Chapter 15

Software development

15.01 Stages in the program development life cycle

软件生命周期

软件的生命周期,亦称软件的生存周期。它是按开发软件的规模和复杂程度,从时间上把软件开发的整个过程(从计划开发开始到软件报废为止的整个历史阶段)进行分解,形成相对独立的几个阶段,每个阶段又分解成几个具体的任务,然后按规定顺序依次完成各阶段的任务并规定一套标准的文档作为各个阶段的开发成果,最后生产出高质量的软件。

1、问题的定义及规划

此阶段是软件开发方与需求方共同讨论,主要确定软件的开发目标及其可行性。

2、需求分析

在确定软件开发可行的情况下,对软件需要实现的各个功能进行详细分析。需求分析阶段是一个很重要的阶段,这一阶段做得好,将为整个软件开发项目的成功打下良好的基础。“唯一不变的是变化本身。”,同样需求也是在整个软件开发过程中不断变化和深入的,因此我们必须制定需求变更计划来应付这种变化,以保护整个项目的顺利进行。

3、软件设计

此阶段主要根据需求分析的结果,对整个软件系统进行设计,如系统框架设计,数据库设计等等。软件设计一般分为总体设计和详细设计。好的软件设计将为软件程序编写打下良好的基础。

4、程序编码

此阶段是将软件设计的结果转换成计算机可运行的程序代码。在程序编码中必须要制定统一,符合标准的编写规范。以保证程序的可读性,易维护性,提高程序的运行效率。

5、软件测试

在软件设计完成后要经过严密的测试,以发现软件在整个设计过程中存在的问题并加以纠正。整个测试过程分单元测试、组装测试以及系统测试三个阶段进行。测试的方法主要有白盒测试和黑盒测试两种。在测试过程中需要建立详细的测试计划并严格按照测试计划进行测试,以减少测试的随意性。

6、运行维护

软件维护是软件生命周期中持续时间最长的阶段。在软件开发完成并投入使用后,由于多方面的原因,软件不能继续适应用户的要求。要延续软件的使用寿命,就必须对软件进行维护。软件的维护包括纠错性维护和改进性维护两个方面。

program development life cycle

Analysis

  1. The first step in solving a problem is to investigate the issues and the current system if there is one. The problem needs to be defined clearly and precisely. A ‘requirements specification’ is drawn up.
  2. The next step is planning a solution. Sometimes there is more than one solution. You need to decide which is the most appropriate.
  3. The third step is to decide how to solve the problem
    1. bottom-up: start with a small sub-problem and then build on this
    2. top-down: stepwise refinement using pseudocode, flowcharts or structure charts.

Design

Plan your algorithm by drawing a flowchart or writing pseudocode.

Coding

When you have designed your solution, you might need to choose a suitable high-level programming language.

You implement your algorithm by converting your pseudocode into program code. When you start writing programs you might find it takes several attempts before the program compiles.

Testing

Only thorough testing can ensure the program really works under all circumstances

There are several different development methodologies. These include the waterfall, the iterative and the rapid application development model.

瀑布模型

瀑布模型将软件生命周期划分:制定计划、需求分析、软件设计、程序编写、软件测试和运行维护等六个基本活动,并且规定了它们自上而下、相互衔接的固定次序,如同瀑布流水,逐级下落。

在瀑布模型中,软件开发的各项活动严格按照线性方式进行,当前活动接受上一项活动的工作结果,实施完成所需的工作内容。当前活动的工作结果需要进行验证,如验证通过,则该结果作为下一项活动的输入,继续进行下一项活动,否则返回修改。

优点:严格遵循预先计划的步骤顺序进行,一切按部就班比较严谨。

  1. 为项目提供了按阶段分的检查点
  2. 当完成一个阶段后,只需要去关注后续阶段
  3. 可在迭代模型中应用瀑布模型

缺点:缺乏灵活性,太过线性理想化,不适合现代软件开发

  1. 各个阶段的划分完全固定,阶段之间产生大量的文档,极大地增加了工作量;
  2. 由于开发模型是线性的,用户只有等到整个过程的末期才能见到开发成果,从而增加了开发的风险;
  3. 早期的错误可能要等到开发后期的测试阶段才能发现,进而带来严重的后果。
  4. 各个软件生命周期衔接花费时间较长,团队人员交流成本大。
  5. 瀑布式方法在需求不明并且在项目进行过程中可能变化的情况下基本是不可行的。

迭代模型

在迭代式开发方法中,整个开发工作被组织为一系列的短小的、固定长度(如3周)的小项目,被称为一系列的迭代。每一次迭代都包括了需求分析、设计、实现与测试。采用这种方法,开发工作可以在需求被完整地确定之前启动,并在一次迭代中完成系统的一部分功能或业务逻辑的开发工作。再通过客户的反馈来细化需求,并开始新一轮的迭代。

迭代和版本的区别,可理解如下:迭代一般指某版本的生产过程,包括从需求分析到测试完成;版本一般指某阶段软件开发的结果,一个可交付使用的产品。

优点:

  1. 降低了在一个增量上的开支风险。如果开发人员重复某个迭代,那么损失只是这一个开发有误的迭代的花费。
  2. 降低了产品无法按照既定进度进入市场的风险。通过在开发早期就确定风险,可以尽早来解决而不至于在开发后期匆匆忙忙。
  3. 加快了整个开发工作的进度。因为开发人员清楚问题的焦点所在,他们的工作会更有效率。
  4. 由于用户的需求并不能在一开始就作出完全的界定,它们通常是在后续阶段中不断细化的。因此,迭代过程这种模式使适应需求的变化会更容易些。因此复用性更高

快速原型模型(The Rapid Application Development (RAD) model)

快速原型模型的第一步是建造一个快速原型,实现客户或未来的用户与系统的交互,用户或客户对原型进行评价,进一步细化待开发软件的需求。通过逐步调整原型使其满足客户的要求,开发人员可以确定客户的真正需求是什么;第二步则在第一步的基础上开发客户满意的软件产品。

显然,快速原型方法可以克服瀑布模型的缺点,减少由于软件需求不明确带来的开发风险,具有显著的效果。

快速原型的关键在于尽可能快速地建造出软件原型,一旦确定了客户的真正需求,所建造的原型将被丢弃。因此,原型系统的内部结构并不重要,重要的是必须迅速建立原型,随之迅速修改原型,以反映客户的需求。

快速原型模型有点整合“边做边改”与“瀑布模型”优点的意味。

优点:

  1. 生命周期短
  2. 整合“边做边改”与“瀑布模型”优点
  3. 减少软件需求不明确带来的开发风险
  4. 适用于小型、交互型的系统,大型系统的某些部分

缺点:

  1. 可能导致系统设计差、效率低、难以维护

The waterfall model

The arrows going down represent the fact that the results from one stage are input into the next stage. The arrows leading back up to an earlier stage reflect the fact that often more work is required at an earlier stage to complete the current stage.

benefits
  • Simple to understand as the stages are clearly defined.
  • Easy to manage due to the fixed stages in the model. Each stage has specific outcomes.
  • Stages are processed and completed one at a time.
  • Works well for smaller projects where requirements are very well understood.
drawbacks
  • No working software is produced until late during the life cycle.
  • Not a good model for complex and object-oriented projects.
  • Poor model for long and ongoing projects.
  • Cannot accommodate changing requirements.
  • It is difficult to measure progress within stages.
  • Integration is done at the very end, which doesn’t allow identifying potential technical or business issues early.

The iterative model

An iterative life cycle model does not attempt to start with a full specification of requirements. Instead, development starts with the implementation of a small subset of the program requirements. Repeated (iterative) reviews to identify further requirements eventually result in the complete system.

Drawback
  • Only large software development projects can benefit because it is hard to break a small software system into further small serviceable modules.
  • More resources may be required.
  • Design issues might arise because not all requirements are gathered at the beginning of the entire life cycle.
  • Defining increments may require definition of the complete system.
Benefits
  • There is a working model of the system at a very early stage of development, which makes it easier to find functional or design flaws. Finding issues at an early stage of development means corrective measures can be taken more quickly.
  • Some working functionality can be developed quickly and early in the life cycle.
  • Results are obtained early and periodically.
  • Parallel development can be planned.
  • Progress can be measured.
  • Less costly to change the scope/requirements.
  • Testing and debugging of a smaller subset of program is easy.
  • Risks are identified and resolved during iteration.
  • Easier to manage risk – high-risk part is done first.
  • With every increment, operational product is delivered.
  • Issues, challenges and risks identified from each increment can be utilised/applied to the next increment.
  • Better suited for large and mission-critical projects.
  • During the life cycle, software is produced early, which facilitates customer evaluation and feedback.

The Rapid Application Development (RAD) model

RAD is a software development methodology that uses minimal planning. Instead it uses prototyping. A prototype is a working model of part of the solution.

In the RAD model, the modules are developed in parallel as prototypes and are integrated to make the complete product for faster product delivery. There is no detailed preplanning. Changes are made during the development process.

The analysis, design, code and test phases are incorporated into a series of short, iterative development cycles.

Benefits
  • Changing requirements can be accommodated.
  • Progress can be measured.
  • Productivity increases with fewer people in a short time.
  • Reduces development time.
  • Increases reusability of components.
  • Quick initial reviews occur.
  • Encourages customer feedback.
  • Integration from very beginning solves a lot of integration issues.
Drawbacks
  • Only systems that can be modularised can be built using RAD.
  • Requires highly skilled developers/designers.
  • Suitable for systems that are component based and scalable.
  • Requires user involvement throughout the life cycle.
  • Suitable for projects requiring shorter development times.

15.02 Program design using structure charts

Key Terms

  • Structure chart - a graphical representation of the modular structure of a solution
  • Parameter - a value passed between modules

structure charts (1)

selection

repretition

structure charts (2)

  • An arrow with a solid round end shows that the value transferred is a flag (a Boolean value)
  • A double-headed arrow shows that the variable value is updated within the module.

15.03 Deriving pseudocode from a structure chart

pseudocode

MODULE Pyramid 
    CALL SetValues(NumberOfSymbols, NumberOfSpaces, Symbol, MaxNumberOfSymbols) 
    REPEAT 
        CALL OutputSpaces(NumberOfSpaces) 
        CALL OutputSymbols(NumberOfSymbols, Symbol) 
        CALL AdjustValuesForNextRow(NumberOfSpaces, NumberOfSymbols) 
    UNTIL NumberOfSymbols > MaxNumberOfSymbols 
ENDMODULE

PROCEDURE SetValues(NumberOfSymbols, NumberOfSpaces, Symbol, MaxNumberOfSymbols) 
    INPUT Symbol
    CALL InputMaxNumberOfSymbols 
    NumberOfSpaces ← (MaxNumberOfSymbols – 1) / 2 
    NumberOfSymbols ← 1 
ENDPROCEDURE

PROCEDURE InputMaxNumberOfSymbols(MaxNumberOfSymbols) 
    REPEAT 
        INPUT MaxNumberOfSymbols 
    UNTIL MaxNumberOfSymbols MOD 2 = 1 
ENDPROCEDURE

PROCEDURE OutputSpaces(NumberOfSpaces) 
    FOR Count ← 1 TO NumberOfSpaces 
        OUTPUT Space // without moving to next line 
    NEXT Count 
ENDPROCEDURE

PROCEDURE OutputSymbols(NumberOfSymbols, Symbol) 
    FOR Count← 1 TO NumberOfSymbols 
        OUTPUT Symbol // without moving to next line 
    NEXT Count 
    OUTPUT Newline // move to the next line 
ENDPROCEDURE

PROCEDURE AdjustValuesForNextRow(NumberOfSpaces, NumberOfSymbols)
    NumberOfSpaces ← NumberOfSpaces – 1 
    NumberOfSymbols ← NumberOfSymbols + 2 
ENDPROCEDURE

15.04 Program design using state-transition diagrams

Key Terms

  • Finite state machine (FSM) - a machine that consists of a fixed set of possible states with a set of inputs that change the state and a set of possible outputs
  • State-transition table - a table that gives information about the states of an FSM
  • State-transition diagram - a diagram that describes the behaviour of an FSM

state-transition diagrams

state-transition table

state-transition diagram

state-transition diagram with outputs

Worked example : Creating a state-transition diagram for an intruder detection system

Description of the system: The system has a battery power supply. The system is activated when the start button is pressed. Pressing the start button when the system is active has no effect. To de-activate the system, the operator must enter a PIN. The system goes into alert mode when a sensor is activated. The system will stay in alert mode for two minutes. If the system has not been de-activated within two minutes an alarm bell will ring.

state-transition table

state-transition diagram

Worked Example:: Creating a state-transition diagram for a two’s complement FSM

state-transition diagram

A finite state machine has been designed that will take as input a positive binary integer, one bit at a time, starting with the least significant bit. The FSM converts the binary integer into the two’s complement negative equivalent. The method to be used is as follows.

1 Output the bits input up to and including the first 1. 2 Output the other bits following this scheme:: 1. For each 1, output a 0. 2. For each 0, output a 1.

state-transition table

15.05 Types of error

Key Terms

  • Syntax error - an error in which a program statement does not follow the rules of the language
  • Logic error - an error in the logic of the solution that causes it not to behave as intended
  • Run-time error - an error that causes program execution to crash or freeze

Why errors occur and how to find them

  • the programmer has made a coding mistake
  • the requirement specification was not drawn up correctly
  • the soft ware designer has made a design error
  • the user interface is poorly designed, and the user makes mistakes
  • computer hardware experiences failure.

15.06 Testing method

Key Terms

  • Test data - carefully chosen values that will test a program
  • Black-box testing - comparing expected results with actual results when a program is run
  • White-box testing - testing every path through the program code
  • Dry-run (walk through) - the process of checking the execution of an algorithm or program by recording variable values in a trace table
  • Trace table - a table with a column for each variable that records their changing values
  • Integration testing - individually tested modules are joined into one program and tested to ensure the modules interact correctly
  • Alpha testing - testing of software in-house by dedicated testers
  • Acceptance testing - testing of software by customers before sign-off
  • Beta testing - testing of software by a limited number of chosen users before general release

测试流程

stub 测试

Stub 的典型应用场景即是当某个对象需要从数据库抓取数据时,我们并不需要真实地与数据库进行交互或者像 Fake 那样从内存中抓取数据,而是直接返回预定义好的数据。

stub testing

You can write a ‘stub’ for each procedure.

The procedure body only contains an output statement to acknowledge that the call was made. Each option the user chooses in the main program will call the relevant procedure.

黑盒测试

黑盒测试是一种软件测试技术,它在不查看软件内部结构或编码的情况下检查软件的功能。黑盒测试的主要来源是客户声明的需求规范。

在这种方法中,测试者选择一个函数并给出输入值来检查它的功能,并检查该函数是否给出了预期的输出。如果函数产生正确的输出,则它在测试中通过,否则失败。测试团队将结果报告给开发团队,然后测试下一个功能。完成所有功能测试后,如果出现严重问题,则反馈给开发团队进行修正。

黑盒测试过程:

  1. 黑盒测试是基于需求的规范,所以从一开始就检查。
  2. 在第二步中,测试人员通过选择有效和无效的输入值来检查软件是否正确或不正确地处理它们,从而创建正面测试场景和负面测试场景。
  3. 第三步,测试人员开发各种测试用例,如决策表、所有对测试、等价划分、误差估计、因果图等。
  4. 第四阶段包括执行所有测试用例。
  5. 在第五步中,测试人员将预期输出与实际输出进行比较。
  6. 在第六步也是最后一步,如果软件有任何缺陷,则将其修复并再次测试。

Black-box testing

As part of thorough testing, a program should also be tested by other people, who do not see the program code and don’t know how the solution was coded.

This method of testing is called black-box testing because the tester can’t see inside the program code:: the program is a ‘black box’.

Once black-box testing has established that there is an error, debugging soft ware or dry-running have to be used to find the lines of code that need correcting.

白盒测试

软件测试的盒测试方法包括黑盒测试和白盒测试。我们在这里讨论白盒测试,也称为玻璃盒测试、结构测试、透明盒测试、开盒测试和透明盒测试。它测试软件的内部编码和基础设施,重点是根据预期和期望的输出检查预定义的输入。它基于应用程序的内部工作原理,并围绕内部结构测试展开。在这种类型的测试中需要编程技能来设计测试用例。白盒测试的主要目标是关注通过软件的输入和输出流并加强软件的安全性。

开发人员进行白盒测试。在此,开发人员将测试程序的每一行代码。开发人员执行白盒测试,然后将应用程序或软件发送给测试团队,在那里他们将执行黑盒测试并验证应用程序以及需求并识别错误并将其发送给开发人员。

开发人员修复错误并进行一轮白盒测试并将其发送给测试团队。在这里,修复错误意味着错误已被删除,并且特定功能在应用程序上运行良好。

White-box testing

How can we check that code works correctly? We choose suitable test data that checks every path through the code. This is called white-box testing.

worked example:: White-box testing of pseudocode
INPUT Number1 
INPUT Number2 
INPUT Number3 
IF Number1 > Number2
    THEN           // Number1 is bigger 
        IF Number1 > Number3 
            THEN 
                OUTPUT Number1 
            ELSE 
                OUTPUT Number3 
        ENDIF
    ELSE           // Number2 is bigger 
        IF Number2 > Number3 
            THEN 
                OUTPUT Number2 
            ELSE 
                OUTPUT Number3 
        ENDIF 
ENDIF

Dry-running an algroithm

A good way of checking that an algorithm works as intended is to dry-run the algorithm using a trace table and different test data. This is also known as a walk through.

Worked example:: Tracing an algorithm
SecretNumber ← 34 
INPUT "Guess a number: " Guess 
NumberOfGuesses ← 1 
REPEAT
    IF Guess = SecretNumber 
        THEN 
            OUTPUT "You took ", NumberOfGuesses, " guesses” 
        ELSE
            IF Guess > SecretNumber 
                THEN 
                    INPUT "Guess a smaller number: " Guess 
                ELSE 
                    INPUT "Guess a larger number: " Guess
            ENDIF 
            NumberOfGuesses ← NumberOfGuesses + 1
    ENDIF 
UNTIL Guess = SecretNumber

Worked example:: Tracing an algorithm
MaxIndex ← 7 
n ← MaxIndex - 1 
REPEAT 
    NoMoreSwaps ← TRUE 
    FOR j ← 1 TO n
        IF MyList[j] > MyList[j + 1] 
            THEN 
                Temp ← MyList[j]
                MyList[j] ← MyList[j + 1]
                MyList[j + 1] ← Temp
                NoMoreSwaps ← FALSE
        ENDIF 
    NEXT j 
    n ← n - 1
UNTIL NoMoreSwaps = TRUE

1

集成测试

集成测试是继单元测试之后的软件测试过程的第二级。在此测试中,软件的单元或单个组件在一组中进行测试。集成测试级别的重点是在集成组件或单元之间交互时暴露缺陷。

一旦所有组件或模块都独立工作,那么我们需要检查依赖模块之间的数据流,这称为集成测试。

  • 只有在应用程序的每个模块上完成功能测试后,我们才会进行集成测试。
  • 我们总是通过逐个模块选择模块来进行集成测试,以便遵循正确的顺序,并且我们不会错过任何集成场景。
  • 首先,确定可以根据测试数据准备可执行测试用例的测试用例策略。
  • 检查应用程序的结构和体系结构,确定要首先测试它们的关键模块,并确定所有可能的场景。
  • 设计测试用例来详细验证每个接口。
  • 选择用于测试用例执行的输入数据。输入数据在测试中起着重要作用。
  • 如果我们发现任何错误,则将错误报告传达给开发人员并修复缺陷并重新测试。
  • 执行正面和负面的集成测试。
Integration testing

Soft ware often consists of many modules, sometimes written by different programmers. Each individual module might have passed all the tests, but when modules are joined together into one program, it is vital that the whole program is tested. This is known as integration testing.

Alpha测试

Alpha 测试在组织中进行,并由开发人员方的具有代表性的最终用户组进行测试,有时由独立的测试人员团队进行测试。

Alpha 测试是在内部站点进行的模拟或真实操作测试。它是在单元测试、集成测试等之后进行的。在执行所有测试之后使用 Alpha 测试。

它可以是白盒测试,也可以是黑盒测试,具体取决于要求——特定的实验室环境和此测试所需的实际环境的模拟。

Alpha 测试是用户验收测试。在产品通过测试阶段并准备发布后执行 Alpha 测试。它在 beta 测试之前执行,这也是验收测试的一部分,可以定义为现场测试。在此测试期间,我们可以对软件进行更改以提高其质量和功能。Alpha 测试在开发人员的站点上完成,独立开发人员可以在其中监视和记录用户体验并进行必要的更改以提高性能。

Alpha 测试是测试的最后阶段。Alpha 测试是一种必不可少且流行的测试技术,可帮助团队交付优质且有用的软件。该测试在产品发布之前进行。Alpha 测试可以定义为确保软件按照需求计划运行的第一轮独立测试。

Alpha testing

Soft ware will be tested in-house by soft ware testers before being released to customers. This type of testing is called alpha testing.

验收测试

验收测试是基于用户需求和功能处理的正式测试。它确定软件是否符合规定的要求和用户要求。它作为一种黑盒测试进行,其中所需用户的数量涉及测试系统的接受程度。它是软件测试的第四个也是最后一个级别。

用户验收测试 (UAT) 是一种测试,由客户在接受最终产品之前完成。通常,UAT 是由客户(领域专家)根据客户(领域专家)的满意度完成的,并根据给定的业务场景、实时场景检查应用程序是否正常工作。

在这方面,我们只关注那些客户经常使用的功能和场景,或者主要是业务的用户场景,或者最终用户或客户日常使用的那些场景。

然而,该软件已经通过了三个测试级别(单元测试、集成测试、系统测试),但在实际场景中最终用户使用系统时仍然可以识别出一些小错误。

验收测试是对之前完成的所有测试过程的压缩。

Acceptance testing

Bespoke soft ware (written for a specific customer) will then be released to the customer. The customer will check that it meets their requirements and works as expected. This stage is referred to as acceptance testing. It is generally part of the hand-over process. On successful acceptance testing, the customer will sign off the soft ware.

Beta测试

Beta 测试是一种现场测试。此测试在软件测试生命周期结束时执行。这种类型的测试可以被视为外部用户验收测试。它是一种显着测试。真实用户执行此测试。此测试在 alpha 测试之后执行。在这个新版本中,向有限的受众发布了 Beta 测试,以检查可访问性、可用性和功能等。

beta测试的特点:

产品测试由软件应用程序的真实用户在真实环境中执行。该软件的 Beta 版发布给有限数量的最终用户,以获取产品质量的反馈。Beta 测试降低了失败的风险,并通过客户验证提供了产品的质量。这是将产品运送给客户之前的最终测试。Beta 测试从客户那里获得直接反馈。它有助于在客户环境中测试产品。

  • Beta 测试在用户站点的真实环境中使用。Beta 测试有助于提供质量的实际位置。
  • 由客户、利益相关者和最终用户执行的测试。
  • Beta 测试总是在 alpha 测试之后,在将其投放市场之前进行。
  • Beta 测试是黑盒测试。
  • Beta 测试在没有测试人员和真实用户存在的情况下进行
  • Beta 测试在 alpha 测试之后和最终产品发布之前进行。
  • Beta 测试通常用于测试实用程序、操作系统和应用程序等软件产品。
Beta testing

When soft ware is not bespoke but produced for general sale, there is no specific customer to perform acceptance testing and sign off the soft ware. So, after alpha testing, a version is released to a limited audience of potential users, known as ‘beta testers’. These beta testers will use the soft ware and test it in their own environments. This early release version is called a beta version and the chosen users perform beta testing. During beta testing, the users will feed back to the soft ware house any problems they have found, so that the soft ware house can correct any reported faults.

15.07 Test strategy, test plans and test data

Test strategy, test plans and test data

  • flow of control:: does the user get appropriate choices and does the chosen option go to the correct module?
  • validation of input:: has all data been entered into the system correctly?
  • do loops and decisions perform correctly?
  • is data saved into the correct files?
  • does the system produce the correct results?
Worked Example

15.08 Corrective maintenance

Corrective maintenance of a program refers to the work required when a program is not working correctly due to a logic error or because of a run-time error.

15.09 Adaptive maintenance

Adaptive maintenance is the action of making amendments to a program to enhance functionality or in response to specification changes.

15.10 Perfective maintenance

Perfective maintenance - modifying a program to improve performance or maintainability

辅助阅读