我是java中的断言概念的新手.我在哪里读过关于java中的断言概念,总是说,如果我们使用assert expression1:expression2,它将使用默认构造函数或AssertionError类中的七个构造函数之一,以防它失败. 但我怀疑的是,当assert语句失败时,谁实际上抛出了这个AssertionError错误?编译器是否会添加" throw new AssertionError(---) ",否则JVM将检查表达式并抛出AssertionError(如ArithmeticException,NullPointerException等...)?
我在python中使用assert.每次断言失败时,我都会得到失败的消息,我会把它放在那里打印.但我想知道在断言条件通过时是否有任何方法可以打印自定义成功消息?我正在使用py.test框架.
例:
assert self.clnt.stop_io()==1, "IO stop failed"
Run Code Online (Sandbox Code Playgroud)
对于上面的断言,如果断言失败,我得到消息"IO stop failed"但是如果assert通过,我希望"IO stop succeeded".就像是
assert self.clnt.stop_io()==1, "IO stop failed", "IO stop succeeded"
Run Code Online (Sandbox Code Playgroud) 我假设标题中有错误,为清楚起见,这里再次
'CityListViewSet' should either include a `serializer_class` attribute,
or override the `get_serializer_class()` method.
Run Code Online (Sandbox Code Playgroud)
我的序列化程序未连接到我的视图,在我的代码中应该如此。我不太确定这个错误在哪里。我想知道你们是否看到过类似的东西?
这是代码。
路由器:
router.register(r'city-list', CityListViewSet, base_name='city-list')
Run Code Online (Sandbox Code Playgroud)
视图:
class CityListViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Venue.objects.values('city').distinct()
serializer = CitySerializer(queryset, many=True)
ordering_fields = ('city',)
ordering = ('city',)
Run Code Online (Sandbox Code Playgroud)
序列化器:
class CitySerializer(serializers.ModelSerializer):
class Meta:
model = City
fields =('city',)
Run Code Online (Sandbox Code Playgroud)
用似乎正确连接的代码会导致这种断言错误的原因是什么?
我希望我的 Laravel 应用程序在开发过程中在浏览器中输出断言错误。尽管我在 Laravel 代码中放置了一些肯定会失败的断言,但我从未在浏览器中看到任何输出错误?
Laravel 中是否有可以强制显示这些错误的断言报告配置?
在生产中,我希望断言失败调用回调方法并将错误通过电子邮件发送给我。
将字符串格式的日期转换为日期时间格式时,我的 python 抛出断言错误。这在“read_csv”中用作转换器。
例如我的数据如下所示:"01-SEP-18 01.30.30.000000 AM"
据我所知,格式应该如下。这不是我的确切代码,但我包含了字符串而不是表达我的转换器。我知道 to_datetime 相对聪明,并且在没有格式的情况下尝试只收到类似/相同的错误。
pn.to_datetime('01-SEP-18 01.30.30.000000 AM','%d-%b-%y %I.%M.%S.%f %p')
pn.to_datetime('01-SEP-18 01.30.30.000000 AM')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\tools\datetimes.py", line 469, in to_datetime
result = _convert_listlike(np.array([arg]), box, format)[0]
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\tools\datetimes.py", line 368, in _convert_listlike
require_iso8601=require_iso8601
File "pandas\_libs\tslib.pyx", line 492, in pandas._libs.tslib.array_to_datetime
File "pandas\_libs\tslib.pyx", line 513, in pandas._libs.tslib.array_to_datetime
AssertionError
Run Code Online (Sandbox Code Playgroud) 给定以下输入:
var customers = new[] {
new Customer { Name = "John", Age = 42 },
new Customer { Name = "Mary", Age = 43 }
};
var employees = new[] {
new Employee { FirstName = "John", Age = 42 },
new Employee { FirstName = "Mary", Age = 43 }
};
Run Code Online (Sandbox Code Playgroud)
使用 FluentAssertions 比较这些列表的最佳方法是什么?
我目前唯一的方法是这样的——与Enumerable.SequenceEqual非常相似:
using (var customerEnumerator = customers.GetEnumerator())
using (var employeeEnumerator = employees.GetEnumerator())
{
while (customerEnumerator.MoveNext())
{
employeeEnumerator.MoveNext().Should().BeTrue();
var (customer, employee) = (customerEnumerator.Current, employee.Current); …Run Code Online (Sandbox Code Playgroud) 有没有办法在雪花中执行断言?
基本上,我正在尝试进行一些测试/TDD,并且我想要一种类似于其他所有语言中的断言的机制:
我需要对我得到的 JS 对象运行断言。这里的问题是,即使我的断言失败,测试仍然显示为通过;我该如何修复它?
\n代码:
\n var expect = require('chai').expect\n const sslCertificate = require('get-ssl-certificate')\n\n describe('ssl certificate verification',()=>{\n it('verifies the issuer of the certificate',()=>{\n sslCertificate.get('instagram.com').then(function (certificate) {\n console.log(typeof certificate.issuer)\n console.log(certificate.issuer.O)\n console.log(certificate.issuer.CN)\n console.log(certificate.subject.CN)\n\n expect(certificate.issuer).to.include({CN: 'DigiCert SHA2 High Assurance Server CA'});\n expect(certificate.issuer).which.is.an('object').to.haveOwnProperty('CN')\n })\n })\n})\nRun Code Online (Sandbox Code Playgroud)\n终端命令:
\nmocha myFile.js\nRun Code Online (Sandbox Code Playgroud)\n输出
\nssl certificate verification\n \xe2\x88\x9a verifies the issue of the certificate\n\n\n 1 passing (46ms)\n\nobject\nDigiCert Inc\nDigiCert SHA2 High Assurance Server CA\n*.instagram.com\nRun Code Online (Sandbox Code Playgroud)\n断言失败,但通过测试输出
\n expect(certificate.issuer).to.include({CN: 'a'});\n\n\n\n ssl certificate verification\n \xe2\x88\x9a verifies the issue …Run Code Online (Sandbox Code Playgroud) 我一直在 julia做一些练习,我目前正在尝试将@assert一个向量对角化为一个矩阵,与练习笔记本中给出的“解矩阵”相对。但是,AssertionError在针对提供的解决方案断言我的代码时,我得到了一个。我的代码示例:
julia> using LinearAlgebra
julia> A =
[
140 97 74 168 131
97 106 89 131 36
74 89 152 144 71
168 131 144 54 142
131 36 71 142 36
]
5×5 Matrix{Int64}:
140 97 74 168 131
97 106 89 131 36
74 89 152 144 71
168 131 144 54 142
131 36 71 142 36
julia> A_eigv = eigen(A).values
5-element Vector{Float64}:
-128.49322764802145
-55.887784553057
42.752167279318854
87.16111477514494 …Run Code Online (Sandbox Code Playgroud) 我的before()挂钩中有以下代码行。
before(() ==> {
cy.get(this.testPopup).then(($el) => {
if ($el.length) {
cy.get(this.testPopupCloseButton).click();
cy.get(this.testPopup).should("not.exist");
}
});
});
Run Code Online (Sandbox Code Playgroud)
会有一个弹出窗口,有时会显示,有时不会。我尝试编写一个逻辑来关闭该弹出窗口,并检查仅当弹出窗口存在时它是否在关闭时消失。
但我收到以下错误。
30000 毫秒后超时重试:期望找到元素:#test-popup-element,但从未找到。
由于此错误发生在 before all 挂钩期间,我们将跳过当前套件中的其余测试`
我基本上期望这里有一个软断言,即使该断言失败,它将继续运行其余的测试。
请指教。