编写有效用例实例Writing effective Use Case Examples

Writing effective Use Case Examples

编写有效用例实例

A great way for writing effective use cases is to walk through a simple use case example and watch how it can be leveraged to something complex. By absorbing the meaning of what use case diagrams, alternate flows and basic flows, you will be able to apply use cases to your projects.

学习编写有效用例的一个很有效的方法就是通过一个小的用例实例,并观察思考怎么利用它来解决复杂的问题。通过理解吸收用例图、备选流程和主流程的含义,就可以将用例的实际应用到你的项目中。

In this section, I'm going to walk you through writing effective use cases for a mock Ebay site. Most of us know and love Ebay, so if you don't know Ebay, go to Ebay and navigate through the site and come back to our example. Imagine that only you know Ebay, but nobody has ever seen Ebay and you have to write the requirements for Ebay using use cases, and explain it to people who have never seen it.

在本节中,我将通过模拟易趣网站来学习编写有效的用例。我们大多数人所了解和喜爱易趣,所以如果你不知道易趣,前往易趣并浏览网站,再回到我们的例子。 设想,除了你知道易趣没有人见过EBay,并且要你通过使用用例写出易趣的需求,并解释给谁从未见过的人听。

STEP 1. To write effective use cases, be productive without perfection

1步。  有效的用例,是有生产价值的、使用的,不是完美的

When it comes to writing effective use cases, you don't need to be a perfectionist and concern yourself with getting it right the first time. Developing use cases should be looked at as an iterative process where you work and refine. You can always refine it later, so again, don't go for perfection from the get-go. Loosen up and have some fun while you're doing it.

在编写用例时,你没有必要确保它的完整性甚至在第一次时也没有必要担忧它的正确性。开发用例是一个不断运行和修正的迭代的过程。You can always refine it later, so again, don't go for perfection from the get-go.您可以随时修正后,因此再次强调,不要一开始就去追求完美。 Loosen up and have some fun while you're doing it.别紧张,这是一个充满乐趣的过程。

STEP 2. Define your use case actors

2步。 Define your use case actors 定义用例的参与者

There are possibly over a dozen actors that interact with Ebay, from buyers and sellers, down to suppliers, wholesalers, auditors, and customer service. But we're going for grass-roots, so who are the basic users of Ebay? BUYERS and SELLERS. So lets put them down as our first actors. (The visual notation in the figures below is based on UML -- Unified Markup Language for Use Cases)

从买家、卖家,到供应商、批发商、审计以及客服,和易趣打交道的参与者可能有十多个。But we're going for grass-roots, so who are the basic users of Ebay?但是我们要从大众出发,谁是eBay的基本用户? BUYERS and SELLERS.买家和卖家。 So lets put them down as our first actors.因此,把它们列为我们第一批参与者。 (The visual notation in the figures below is based on UML -- Unified Markup Language for Use Cases) (下图是基于UML -统一标记语言的用例)



Do you notice how the actors aren't John and Sue which would be people? While John may be a seller and Sue may be a buyer, an actor is a Role. And a role in this case would be that of a buyer and that of a seller. Now that things are clicking, lets throw some more actors on your paper just so we can try and identify more possible users.

你是否注意到参与者不是像约翰和休这样实际的人?While John may be a seller and Sue may be a buyer, an actor is a Role.参与者就是一种角色扮演,如约翰可能是卖方和休可能是买家。并且在我们这个案例中,还有既是买家又是卖家的角色。And a role in this case would be that of a buyer and that of a seller.Now that things are clicking, lets throw some more actors on your paper just so we can try and identify more possible users.现在,让我们将更多的参与者列到纸上,来帮助我们的尝试和确认更多的可能参与者。


Now we have a bunch of actors. Wait a minute? Paypal? That's not a person. An actor can be a system, because a system plays another role in the context of your new system and has goals and interacts with other actors as you will see later.

现在我们有一大堆的角色。 Wait a minute?等一下? Paypal?贝宝公司? That's not a person.这不是一个人。 An actor can be a system, because a system plays another role in the context of your new system and has goals and interacts with other actors as you will see later.一个参与者可以是一个系统,因为这个系统在您的新系统中扮演另一个角色,它有自己的任务以及与其他参与者的交互。

STEP 3. Define your use case Actor Goals

3步。  定义您的参与者内容

Now that you have established your actors (system users), or most of them, the next logical step is to outline what the goals are of each actor. One you have established your actors and the goals of each actor, you have now created your initial list of high level use cases. In the example below you will see the representation of actor goals. Again, don't try and capture 100% of this step, in requirements management, refinement is always part of the entire process. Effective use cases should have understandable actors and goals.

现在您已经确定您的参与者(系统用户) ,或者大多数,按逻辑下一步就要列出每个参与者的内容大纲。 你已经确定参与者和每个参与者的内容,现在,你已经建立了初步的主要参与者的列表。在下面的例子中,您将看到的代表性演员内容。再次,不要图捕这一步试获100 %的参与者,在需求管理,完善修改始终贯穿于整个过程。 有效的用例应该包含明了的参与者和确定的目标任务的。 

STEP 4. Identify reuse opportunity for use cases

4步。  确定用例重用的情况

In this step, you are going to cross the bridge into object modeling. Don't get overly concerned about terms like generalization, inheritance and extends. The goal of this Ebay use case example is to keep it understandable so we will explain this concept in terms of the example.

在这个步骤中,你会了解到对象建模。 不要过分担心诸如泛化,继承和扩展。为了能更好的理解本文,我们将举例解释一下这些概念。

What does the word general mean? Something is broad and not as detailed. Generalization is when you "inherit" from something general and then add more detail. A "person" is very general. A "man" is still general, but not as general as a "person". You can say that a "man" inherits behavior and atributes of a "person".

一般这个词是什么意思?广泛的不是具体的事物。 泛化是你从一般的东西中“继承”,然后添加更多的细节。  “人”是非常普遍。 一个“男人”仍是一般,但没有 “人”更广泛 你可以说, “男人”是继承行为和属性的“人”

Look at the requirements management use case diagram above and you will see there is duplicate behavior in both the buyer and seller which includes "create an account" and "search listings". Rather than have all of this duplication, we will have a more general user that has this behavior and then the actors will "inherit" this behavior from the new user.

通过上边需求管理用例图,您将会看到买方和卖方都有重复的“创建帐户”和“搜索列表”行为。 与其都存在这个重复的部分,还不如建立一个拥有这些行为的更一般的参与者,然后其他新的参与者将“继承”这个参与者的行为。

The above use case example diagram illustrates that a generic user creates accounts and search listings and that a buyer and a seller have their own behavior but also have the behavior of the generic user. The benefits of generalization are that you eliminate duplicate behavior and attributes that will ultimately make the system more understandable and flexible. We will see in later steps that this inheritance applies both to use cases and to the actors.

上述用例图说明,建立一个一般的参与者有创建帐户和并搜索列表的行为,并且买方和卖方不但有自己的行为,还有一般参与者的行为。 泛化的好处是可以消除重复的行为和属性,使该系统更容易理解和灵活。 我们将在以后的步骤看到,这继承关系适用于用例和参与者。

STEP 5. Create a use case index

5步。  创建一个用例索引

After producing your initial visual list of use case actors and goals, we can take this list and create an initial use case grid which provides the basis for the use case index. Every use case will have various attributes relating both to the use case iteself and to the project. At the project level, these attributes include scope, complexity, status and priority.

在产生初步的参与者及其目标的列表后,我们就可以根据这个列表,就初步建立一个包含基本用例索引的用例表单。每个用例都会包含用例之间以及用例和项目之间的各种各样的属性。在项目级属性中,包括范围,复杂性,状态和优先级。

This use case index should be used by the project team to define the use cases against. It will serve as a master inventory to help writ effective use cases for the requirements phase of the project.

这个用例索引将是整个项目成员定义用例的依据。在项目需求阶段,把它作为主要清单对能写有效的用例来说,很有帮助。

STEP 6. Identify the key components of your use case

步骤6   确定用例的关键部分

The actual use case is a textual representation illustrating a sequence of events. In our use case example, you will see that there are several components of a use case which we will review. In the mean time, review the table below to get a basic understanding of what is in the use case and then we will review each element as we progress through our use case example.

实际上用例是以文字形式表现的一系列事件的详细说明。在这个用例实例,你会看到,我们将继续分析那个用例包含的几个组成部分。 在此同时,通过下表对用例作基本的了解,随后我们再通过实例说明其每个元素的意思。

Use Case Element

Description

Use Case Number

ID to represent your use case

Application

What system or application does this pertain to

Use Case Name

The name of your use case, keep it short and sweet

Use Case Description

Elaborate more on the name, in paragraph form.

Primary Actor

Who is the main actor that this use case represents

Precondition

What preconditions must be met before this use case can start

Trigger

What event triggers this use case

Basic Flow

The basic flow should be the events of the use case when everything is perfect; there are no errors, no exceptions. This is the "happy day scenario". The exceptions will be handled in the "Alternate Flows" section.

Alternate Flows

The most significant alternatives and exceptions

 

Use Case Element用例元素

Description描述

Use Case Number用例编号

ID to represent your use case编号

Application应用平台

否涉及到What system or application does this pertain to什么系统或应用程序

Use Case Name用例名称

用例The name of your use case, keep it short and sweet名称,保持言简意赅

Use Case Description用例描述

Elaborate more on the name, in paragraph form.一段建一段详细的描述

Primary Actor主要参与者

Who is the main actor that this use case represents代表用例的主要参与者

Precondition先决条件

What preconditions must be met before this use case can start 可以使用的先决条件

Trigger触发事件

What event triggers this use case什么事件触发此用例

Basic Flow基本流程

The basic flow should be the events of the use case when everything is perfect; there are no errors, no exceptions.基本流程是理想状态下的事件流没有任何错误,没有异常。 This is the "happy day scenario".这是快乐的日子的情况。 The exceptions will be handled in the "Alternate Flows" section.yichang 异常情况将在 替代流程一节处理的。

Alternate Flows替代流程

The most significant alternatives and exceptions主要的替代流程和异常情况的事件流程

 

STEP 7. Name and briefly describe your use case

7步。  用例的名称和简要说明

Now that you have a general understanding of what a use case consists of, we are ready to start creating our use case. Typically, while the name of your use case is being discussed, people will start briefly describing the use case. Use plain english and keep it simple. Getting back to our use case example, I will begin with use case #1 from step number four.

现在,你对用例的组成有了全面的了解,我们准备开始创建文明的用例了。通常情况下,大家都会从用例的简要描述开始,因为名称需要大家共同商讨。使用常见英文并保持简单。回到我们的用例#1,从第四步开始把。

Use Case Number:

1

Use Case Name:

Buyer Places a Bid

Description:

An EBAY buyer has identified an item they wish to buy, so they will place a bid for an item with the intent of winning the auction and paying for the item.

 

用例编号:

1 1

Use Case Name:用例名称:

Buyer Places a Bid买家开始竞价

Description:描述:

An EBAY buyer has identified an item they wish to buy, so they will place a bid for an item with the intent of winning the auction and paying for the item.易趣买家选定希望买的东西,开始竞价,并拍卖到自己想要的东西。

 

STEP 8. Create the use case basic flow

步骤8 创建用例基本流程

The basic flow of a use case represents the most important course of events or what happens most of the time, sometimes referred to as the 'Happy Day Scenario' because it is what occurs when everything goes well -- no errors or exceptions. Another reason why the basic flow is so critical is because it's much easier to fully comprehend the exceptions once the norm is understood and if the basic flow represents 70% of the system, the development staff is much more prone to implementing the correct code in the first pass.

基本流程代表着最重要的事件流情况或执行过程中发生在大多数情况下的情况,有时被称为'幸福的一天的场景' ,因为它所有的情况一切顺利-没有任何错误或异常。基本流程如此重要的另一个原因是在基本流程被理解和规范后,人们更容易充分理解各种异常,并且如果基本流程代表70 %的系统功能的话,开发人员更容易一次性正确的代码实现。

For our use case example, the basic flow should be to describe the happy day scenario for your use cases such as "placing a bid". For a consumer to play a successful bid, what is the primary flow when everything goes as planned. An effective use cases needs to have the basic flow before moving forward with writing the alternate flows.

在我们实例的用例中,基本流程应该是描述快乐的日子的情况,如“在出价” 对于消费者成功竞标,就像我们设想的一样去描述主要流程。 一个有效的用例需要在写替代流程之前有基本的流程。

STEP 9. Create the use case alternate flows

步骤9   建立用例替代流程

The basic flow is the key ingredient to your use case and some can argue that you can stop once you're done with the basic flow. It really depends on the level of detail you wish to achieve. However, providing more detail to the consumers of your use case is always a good thing.

基本流程是用例的主要部分,一些因素也会使你停止正常的流程。这实际取决于你想达到的详细程度。当然,给客户提供更详细的用例始终是件好事。


The alternate flows providing the following:

o    An exception or error flow to any line item in your basic flow

o    An additional flow, not necessarily error based, but a flow that COULD happen

A few examples of alternate flows are:

o    While a customer places an order, their credit card failed

o    While a customer places an order, their user session times out

o    While a customer uses an ATM machine, the machine runs out of receipts and needs to warn the customer

下面是替代流程:

  • 基本流程中的任意一个异常或错误
  • 额外的流程,但不一定错误的,而是一个可能发生的流程

替代流程的几个例子

  • 在客户下订单时,他们的信用卡出错了
  • 在客户下订单时,其用户会话超时
  • 当客户使用ATM机时,机器打印出收据并需要给客户发出警告

 

STEP 10. Produce your effective use case document

10步。  形成有效用例的文档

Recently at a new project assignment, I introduced a mid level developer to the concept of use cases which was totally foreign to him. Once walking him through the basic concepts and showing him the use case example, the lightbulb went off in his head on how convenient and simple it was to grasp the project.

最近在一个新的项目交接中,我一个一点都不了解用例中级的开发人员介绍这个概念。一边介绍基本的概念,一边给他看用例的实例,这样很方面和简单的让他掌握这个项目。

 

A few reasons why it's that much easier to learn a system through use cases then a traditional requirements document is probably because with use cases, you are introduced to concepts at a high level, walk through a living scenario and then presented with specifications last.

通过学习用例比传统的文档更易掌握一个系统有几个原因,那就你通过实际的场景和规范的文档,在较高的层次介绍一个系统。

In several places in this document, I have stated "effective use cases" rather than just "use cases". The purpose of the use cases is for effective knowledge transfer from the domain expert to the software developer -- these use cases will serve as software requirements. If they don't make sense to the person building the software, they are not effective. There are several sources on the web for writing effective use cases including the book by Alistair Cockburn.

在本文的很多地方,我强调“有效用例” ,而不是仅仅“用例” 。用例能有效的帮助我们将一个领域的专家知识转换为开发者需要的信息,也就是软件开发的需求。如果这对开发者没有产生作用的话,这些用例将是无效的。网上有不少关于阿利斯泰尔科伯恩写的有效用例这本书的资源。

STEP 11. Generate a Use Case Model Diagram

11步。  生成一个用例模型图

You can use the Gatherspace.com use case modeling tool to produce a use case model within a few clicks. Once you define your use cases and actors, just go into the reporting section and click on the 'Use Case Model' report and that's it. From the main use case model, you can continue to drill down into the use cases.

您可以使用Gatherspace.com上的用例建模工具,方便的产生一个用例模型。一旦您确定您的用例和参与者,只需要进入报告那个步骤,并点击用例模型报告,就是这样。 从主用例模型,您可以继续深入其他用例。

To see what this looks like, click the use case model sample now..

看看他神秘的样子吧,现在就请点击用例模型例子。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编写有效用例的目的是为了确保软件系统的需求和功能能够被准确地传达给开发团队,并且能够帮助测试团队进行测试和验证。以下是编写有效用例的步骤: 1. 确认需求:首先,要明确软件系统的需求和功能,包括用户需求、系统需求以及各种功能模块的需求。 2. 识别参与者:根据软件系统的功能和需求,识别出所有可能涉及的参与者,例如系统管理员、普通用户等。 3. 编写用例标题:为每个功能和需求编写一个明确的用例标题,用于简洁地描述用例的目标和功能。 4. 描述前置条件:在每个用例中,要明确规定该用例执行的前置条件,例如用户登录系统等。 5. 定义主要步骤:在每个用例中,要详细描述实现该功能或需求的主要步骤,以确保开发团队能够理解和实现。 6. 列举其他步骤和可选步骤:在编写用例时,还需要考虑可能出现的其他步骤和可选步骤,以便更全面地描述和测试该功能。 7. 描述预期结果:对于每个用例,要明确规定该功能或需求的预期结果,以便测试团队进行验证。 8. 编写扩展步骤:在编写用例时,还应考虑到可能出现的异常情况和错误处理的扩展步骤。 9. 检查和修订用例编写用例后,应仔细检查和修订,确保用例的完整性和准确性。 10. 与相关方进行确认:最后,要将编写用例与相关方进行确认,包括需求方、开发团队和测试团队,以确保对用例的共识和理解。 通过以上步骤,就能编写出具有准确性、完整性和易读性的有效用例,从而提高开发效率和测试质量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值