注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

阿弥陀佛

街树飘影未见尘 潭月潜水了无声 般若观照心空静...

 
 
 

日志

 
 
关于我

一直从事气象预报、服务建模实践应用。 注重气象物理场、实况场、地理信息、本体知识库、分布式气象内容管理系统建立。 对Barnes客观分析, 小波,计算神经网络、信任传播、贝叶斯推理、专家系统、网络本体语言有一定体会。 一直使用Java、Delphi、Prolog、SQL编程。

网易考拉推荐

ScalaTest User Guide5  

2014-07-04 23:25:12|  分类: Scala |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
ScalaTest User Guide

Getting started

Selecting testing styles

Defining base classes

Writing your first test

Using assertions

Tagging your tests

Running your tests

Sharing fixtures

Sharing tests

Using matchers

Testing with mock objects

Property-based testing

Using Selenium

Other goodies

Philosophy and design

Migrating to 2.0

Tagging your tests

ScalaTest allows you to define arbitrary test categories, to "tag" tests as belonging to those categories, and filter tests to run based on their tags. For example, you could tag some tests as being slow and chose to exclude the slow tests during some runs. ScalaTest supports one tag by default: ignore. You can tag a test as ignored to "switch it off" temporarily.

Tagging tests as ignored

To support the common use case of “temporarily” disabling a test, with the good intention of resurrecting the test at a later time, each style trait provides a way to tag tests as ignored. For example, in a FlatSpec you can change an it or an in to ignore:

import org.scalatest.FlatSpec
import scala.collection.mutable.Stack

class StackSpec extends FlatSpec {
"A Stack" should "pop values in last-in-first-out order" in { val stack = new Stack[Int] stack.push(1) stack.push(2) assert(stack.pop() === 2) assert(stack.pop() === 1) }
ignore should "throw NoSuchElementException if an empty stack is popped" in { val emptyStack = new Stack[String] intercept[NoSuchElementException] { emptyStack.pop() } } }

If you run this version of StackSpec in the Scala interpreter with:

scala> (new StackSpec).execute()

It will run only the first test and report that the second test was ignored:

A Stack
- should pop values in last-in-first-out order
- should throw NoSuchElementException if an empty stack is popped !!! IGNORED !!!

Defining and using your own tags

Each style trait provides a way to tag tests. To tag tests in a FlatSpec, for example, you pass objects that extend abstract class org.scalatest.Tag to taggedAs just before the in. Class Tag takes one parameter, a string name. Here's how you might define tags to mark tests that are slow or require a database:

import org.scalatest.Tag

object SlowTest extends Tag("com.mycompany.tags.SlowTest") object DbTest extends Tag("com.mycompany.tags.DbTest")

Given these definitions, you could tag FlatSpec tests like this:

import org.scalatest.FlatSpec

class ExampleSpec extends FlatSpec {
"The Scala language" must "add correctly" taggedAs(SlowTest) in { val sum = 1 + 1 assert(sum === 2) }
it must "subtract correctly" taggedAs(SlowTest, DbTest) in { val diff = 4 - 1 assert(diff === 3) } }

This code marks both tests with the com.mycompany.tags.SlowTest tag, and test "The Scala language should subtract correctly" with the com.mycompany.tags.DbTest tag.

When executing a suite, tests can optionally be included and/or excluded (i.e., filtered) based on their tags. Here's how:

Next, learn about running your tests.

ScalaTest is brought to you by Bill Venners, with contributions from several other folks. It is sponsored by Artima, Inc.
ScalaTest is free, open-source software released under the Apache 2.0 license.

Copyright ? 2009-2013 Artima, Inc. All Rights Reserved.

artima

  评论这张
 
阅读(491)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017