Tests which rely heavily on fixtures are brittle and can be difficult to maintain. This episode will show a couple techniques for creating tests which don't use fixtures.
# cart_test.rb
def test_total_weight_should_be_sum_of_line_item_weights
cart = Cart.new
cart.line_items.build.stubs(:weight).returns(7)
cart.line_items.build.stubs(:weight).returns(3)
assert_equal 10, cart.total_weight
end
# line_item_test.rb
def test_should_have_zero_for_weight_when_not_shipping
line_item = LineItem.new
line_item.build_delivery_method(:shipping => false)
assert_equal 0, line_item.weight
end
def test_should_have_weight_of_product_times_quantity_when_shipping
line_item = LineItem.new(:quantity => 3)
line_item.build_delivery_method(:shipping => true)
line_item.build_product(:weight => 5)
assert_equal 15, line_item.weight
end
分享到:
相关推荐
在Laravel框架中,`laravel-fixtures`通常指的是数据 fixtures,这是一种用于填充数据库测试数据的方法。Fixtures在软件开发中扮演着重要角色,尤其是在进行集成测试时,它们提供了预定义的数据环境,使得测试更加可...
在Laravel框架中,"Laravel开发-l5-fixtures"是一个专注于数据 fixtures 的包,用于在测试环境中快速填充数据库。Laravel 5引入了更强大的测试工具,而 fixtures 是其中重要的一部分,它允许开发者创建模拟数据,以...
Learn CakePHP: With Unit Testing by Rādhārādhya Dāsa 2016 | ISBN: 1484212134 | English | 114 pages | EPUB | 1 MB Accelerate your development of ... You'll learn about unit testing and how to ...
** Sequelize-Fixtures:前端开发中的数据库测试利器** 在前端开发中,数据库的测试往往是一项不可或缺的任务。Sequelize-Fixtures 是一个针对 Sequelize ORM 的开源库,它专门设计用于帮助开发者快速、方便地创建...
3. **灵活的夹具(fixtures)机制**:夹具是pytest中的一个核心概念,它们允许开发者定义复用的测试资源,如数据库连接或模拟对象等,从而减少重复代码,提高测试的可读性和维护性。 4. **丰富的插件生态系统**:...
Accelerate your development of ... You'll learn about unit testing and how to implement it in CakePHP. This approach to coding leads to better code, better applications, and better programming habits....
### Django单元测试中Fixtures的使用方法 #### 一、引言 在开发基于Django框架的应用程序时,单元测试是确保代码质量和功能正确性的关键环节。为了有效地进行单元测试,通常需要创建一些预设的数据集,这些数据集...
- 显式、模块化、可扩展的Fixtures:pytest的fixtures非常灵活,可以用于任何需要的测试场景。 - Fixture的最终化/执行清理代码:在测试完成后执行必要的清理操作。 - Fixtures可以内省请求的测试上下文:fixtures...
Fixtures 是 Pytest 的核心功能,它们提供了一种定义共享资源的方法,如数据库连接、临时目录等。Fixtures 可以作为参数传递给测试函数,确保每个测试用例都有独立的环境。 ```python import pytest @pytest....
美敦力Medtronic PB 560呼吸机第二部分2 Manufacturing Fixtures Mechanical Part Drawings 第二部分过大,第二部分拆分两部分,而第一部分,第三部分打包一起: 美敦力Medtronic PB 560呼吸机设计规格、软件代码+...
Symfony orm-fixtures 组件的安装和使用 Symfony 是一个流行的 PHP 框架,orm-fixtures 是其下的一个组件,用于加载假数据到数据库中,以便于测试和开发。本文将详细介绍 orm-fixtures 组件的安装和使用。 首先,...
What if a ticket has been closed without a fix? 367 Tracking down unreported problems 368 Where to ask questions 369 Tips on asking questions that will get good answers 370 Opening a new ticket to...
而当涉及到数据库操作的测试时,Django提供了Fixtures功能,使得测试环境可以预加载特定的数据,以便更好地模拟真实情况。本篇文章将深入探讨Django单元测试中Fixtures的用法。 首先,让我们了解什么是Fixtures。在...
1. **No Connections**: Learn cables without any connections to establish baseline signatures. 2. **Single-Ended Cables**: Document single-ended cables for specific testing scenarios. #### Documenting...
GeoJSON-Fixtures库是一个专门针对GeoJSON的数据集,它提供了一系列预定义的测试和验证用例,帮助开发者在构建与GeoJSON相关的应用程序或工具时进行有效的测试。 "前端开源库-geojson-fixtures"是这个项目的核心...
为了有效地测试和开发基于Elasticsearch的应用程序,我们经常需要在测试阶段填充一些模拟数据,这通常被称为Fixtures。"在Node.js上为Elasticsearch加载简单的Fixtures"是一个关键任务,它能帮助开发者快速地设置...
`pytest-server-fixtures` 是一个Python测试框架`pytest`的扩展库,主要用于简化在测试中设置和管理服务器环境。这个库的版本为1.0.1,被封装在一个名为`pytest-server-fixtures-1.0.1.tar.gz`的压缩包内。这个...
meteor add ryne:fixtures 2. 在您的系统上安装 。 在大多数发行版中,这可能与 mongodb 包捆绑在一起。 3. 将函数添加到您的服务器专用 Meteor 方法中。 if ( Meteor . isServer ) { typeof Fixtures !== '...