标签: assertion

在rspec中,为什么我不能在辅助类中使用be_false等?

当使用带有rspec测试的助手类时,我看不到使用这个.should be_false成语.在helper .rb文件中定义的函数中没有问题,但是当它在类中时,be_false找不到符号.以下示例 - 为什么这不起作用?我如何be_false在助手中使用et al?

似乎有可能这样的断言只能在测试中起作用.我有帮助因为例如因故障而失败.网络通信问题实际上是真正的测试失败,因为我的帮助者使用的网络通信是被测系统的一部分.我应该如何让我的测试在helper类中优雅地失败?

结果

$ spec ./test.rb 
helper_foo 1
helper_foo 2
helper_foo 3
FunctionFoo 1
F

1)
NameError in 'my_test should test that helper classes can use should be_false etc'
undefined local variable or method `be_false' for #<HelperFoo:0x2b265f7adc98>
./helper.rb:13:in `FunctionFoo'
./test.rb:13:

Finished in 0.004536 seconds

1 example, 1 failure
Run Code Online (Sandbox Code Playgroud)

test.rb

require "helper.rb"

describe "my_test" do
    it "should test that helper classes can use should be_false etc" do

        (1 == 1).should …
Run Code Online (Sandbox Code Playgroud)

ruby rspec helper assertion

3
推荐指数
1
解决办法
1252
查看次数

Zend ACL动态断言

我想限制我的用户只编辑/删除他们添加的评论.我在youtube上找到了一个名为intergral30的人并按照他的指示操作的例子.现在我的管理员帐户可以编辑/删除所有内容,但我的用户无法访问自己的评论.

这是代码:资源

class Application_Model_CommentResource implements Zend_Acl_Resource_Interface{
public $ownerId = null;
public $resourceId = 'comment';

public function getResourceId() {
    return $this->resourceId;
}
}
Run Code Online (Sandbox Code Playgroud)

角色

class Application_Model_UserRole implements Zend_Acl_Role_Interface{
public $role = 'guest';
public $id = null;

public function __construct(){
    $auth = Zend_Auth::getInstance();
    $identity = $auth->getStorage()->read();

    $this->id = $identity->id;
    $this->role = $identity->role;
}

public function getRoleId(){
    return $this->role;
}
}
Run Code Online (Sandbox Code Playgroud)

断言

class Application_Model_CommentAssertion implements Zend_Acl_Assert_Interface
{
public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $user=null,
            Zend_Acl_Resource_Interface $comment=null, $privilege=null){
    // if role is admin, he can …
Run Code Online (Sandbox Code Playgroud)

acl zend-framework dynamic assertion

3
推荐指数
1
解决办法
2286
查看次数

UIAlertView崩溃iOS7 - 断言失败

关于UIAlertViewiOS7,我有一个问题.当我启动我的应用程序时,它会崩溃,并显示以下消息:

*** Assertion failure in -[UIKeyboardTaskQueue performTask:], /SourceCache/UIKit_Sim/UIKit-2903.2/Keyboard/UIKeyboardTaskQueue.m:388
Run Code Online (Sandbox Code Playgroud)

错误发生在以下行:

- (IBAction)updatePositions:(id)sender{
     _alert = [[UIAlertView alloc] initWithTitle:@"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
     [_alert show];     <====== IT CRASHS HERE
     [NSThread detachNewThreadSelector:@selector(updateDataThread) toTarget:self withObject:nil];
}
Run Code Online (Sandbox Code Playgroud)

我正在使用ARC,并且属性_alert设置定义为:@property (nonatomic,strong)

这个错误看起来很奇怪,因为在iOS6上代码运行完美,我不知道在iOS7上应该有什么不同.

有谁知道错误是什么?

提前致谢.

uikit uialertview uikeyboard assertion ios7

3
推荐指数
1
解决办法
3442
查看次数

生成器对象上的断言

是否有用于内省生成器对象的技术(例如单元测试中的断言)?

更具体地说,我有一个数据处理管道,由一系列小函数组成,这些函数通常应用于列表理解或生成器表达式内的值,如下所示:

生成一些随机数据:

>>> raw_data = ["${}".format(RND.randint(10, 100)) for c in range(10)]

>>> # a function that does some sort of of transform
>>> fnx = lambda q: float(q.replace('$', ''))

>>> d1 = [fnx(itm) for itm in raw_data]
Run Code Online (Sandbox Code Playgroud)

在下一步中,另一个变换函数将应用于d1的项目,依此类推。

在上面的例子中,例如,关于prices_clean的长度或其值的最小/最大等的断言是我的单元测试套件的核心:

>>> assert len(d1) == 10
Run Code Online (Sandbox Code Playgroud)

鉴于我只是要迭代这些中间结果,我实际上不需要列表,生成器对象就可以了,并且考虑到内存配置文件要低得多,这就是我使用的:

>>> d1 = (fnx(itm) for itm in raw_data)
Run Code Online (Sandbox Code Playgroud)

当然,我在使用列表推导式时所依赖的断言不适用于生成器对象:

>>> d1
  <generator object <genexpr> at 0x106da9230>

>>> assert len(d1) == 10
  Traceback (most recent call last):
  File "<pyshell#33>", line 1, …
Run Code Online (Sandbox Code Playgroud)

python unit-testing generator assertion

3
推荐指数
1
解决办法
7399
查看次数

Watir 检查文本存在

我得到它不是 Watir 结合 rspec 找到我的文本。以下代码导致此错误。

  1. 代码:browser.text.include?("Coverberechnung").should == true
  2. 错误 1: expected: true got: false (using ==)
  3. 错误2: Using should from rspec-expectations' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should instead. Called from

也许我可以帮忙

该站点的 URL:在此处输入链接描述

ruby rspec watir assertion watir-webdriver

3
推荐指数
1
解决办法
9448
查看次数

Streams中的断言

我知道我可以过滤流只获取那些非空的元素,然后随心所欲地使用它们.像这样的东西:

myList.stream().filter(element -> element != null).doOtherThings...
Run Code Online (Sandbox Code Playgroud)

有没有办法断言元素在流函数中不为空,以便它遍历所有元素,如果它发现一个为null,它会抛出异常?我一直在考虑以下内容:

myList.stream().assert(Objects::nonNull).doOtherThings...
Run Code Online (Sandbox Code Playgroud)

java assertion java-stream

3
推荐指数
2
解决办法
453
查看次数

如何在 JestJs 中对 TypeScript 类的构造函数中抛出的异常进行单元测试

我正在构建一些应用程序NestJs,因此默认的单元测试框架是JestJs. 假设我有以下类 My.ts

export My {
    constructor(private myValue: number) {
       if (myValue ==== null) {
           throw new Error('myValue is null');
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经创建了单元测试类 My.spec.ts

import { My } from './My';

describe('My', () => {
    fit('Null my value throws', () => {
        expect(new My(null)).rejects.toThrowError('myValue is null');
    });
});
Run Code Online (Sandbox Code Playgroud)

我使用命令npm run test来运行单元测试,而不是得到我所期望的结果,我无法抱怨My类构造函数中的代码抛出异常。

在 Jest 中编写单元测试代码来测试构造函数中的异常逻辑的正确方法是什么?

unit-testing exception assertion typescript jestjs

3
推荐指数
1
解决办法
4454
查看次数

如何在 Cypress 中定义自定义断言运算符?

在 Cypress 测试中,我经常需要检查 DOM 元素中的文本是否等于某个预期的测试。但由于文本周围可能有一些空格,我不能简单地写:

cy.get('.cell')
  .should('have.text', 'Hello')
Run Code Online (Sandbox Code Playgroud)

相反,我必须写:

cy.get('.cell')
  .then($cell => $cell.text().trim())
  .should('eq', 'Hello')
Run Code Online (Sandbox Code Playgroud)

我想定义一个像 的自定义断言运算符have.text.trimmed,允许我像这样使用它:

cy.get('.cell')
  .should('have.text.trimmed', 'Hello');
Run Code Online (Sandbox Code Playgroud)

但是我在官方网站上找不到任何关于它的文件。有人会分享一些例子吗?

assertion cypress

3
推荐指数
2
解决办法
2308
查看次数

断言 testcafe 中是否存在包含特定文本的 td DOM

我刚刚开始使用 testcafe,到目前为止,我发现文档有助于进行测试和自动化 E2E。

我想断言 td 中是否存在一个值,如下所示:

async checkBankAccount(accountNumber, currencyCode){
         const formatedAccount = formatBankAccount(accountNumber, currencyCode);
         console.log(formatedAccount);
         await t
         .expect(Selector('td').withText(formatedAccount).innerText).eql(formatBankAccount);
     }
Run Code Online (Sandbox Code Playgroud)

我遇到以下错误:

未指定断言方法。

我想断言我的 HTML 中是否存在包含 formatedAccount 文本的 td。

谢谢

javascript testing dom assertion testcafe

3
推荐指数
1
解决办法
917
查看次数

tensorflow.python.framework.errors_impl.InvalidArgumentError:无效参数:断言失败:

在使用来自 Google Colab 的 TensorFlow Object Detection API 进行训练时,我收到以下错误(以下详细内容中有两个类似的错误......其中一个在它的末尾):

WARNING:tensorflow:Forced number of epochs for all eval validations to be 1.
W0528 21:13:21.113062 140292083513216 model_lib.py:717] Forced number of epochs for all eval validations to be 1.
INFO:tensorflow:Maybe overwriting train_steps: 200000
I0528 21:13:21.113316 140292083513216 config_util.py:523] Maybe overwriting train_steps: 200000
INFO:tensorflow:Maybe overwriting use_bfloat16: False
I0528 21:13:21.113430 140292083513216 config_util.py:523] Maybe overwriting use_bfloat16: False
INFO:tensorflow:Maybe overwriting sample_1_of_n_eval_examples: 1
I0528 21:13:21.113519 140292083513216 config_util.py:523] Maybe overwriting sample_1_of_n_eval_examples: 1
INFO:tensorflow:Maybe overwriting eval_num_epochs: 1
I0528 21:13:21.113614 140292083513216 config_util.py:523] Maybe …
Run Code Online (Sandbox Code Playgroud)

python invalid-argument assertion tensorflow google-colaboratory

3
推荐指数
2
解决办法
7043
查看次数