assert

python assert的作用

旧巷老猫 提交于 2019-12-04 04:41:38
一、python assert的作用: 根据Python 官方文档解释(https://docs.python.org/3/reference/simple_stmts.html#assert), "Assert statements are a convenient way to insert debugging assertions into a program". 二、一般的用法是: assert condition 用来让程序测试这个condition,如果condition为false,那么raise一个AssertionError出来。逻辑上等同于: if not condition: raise AssertionError() 比如如下的例子: >>> assert 1==1 >>> assert 1==0 Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> assert 1==0 AssertionError >>> assert True >>> assert False Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> assert False

ATTR ObjectMonitor::exit(bool not_suspended, TRAPS)

筅森魡賤 提交于 2019-12-04 04:18:11
1 void ATTR ObjectMonitor::exit(bool not_suspended, TRAPS) { 2 3 Thread * Self = THREAD ; 4 5 if (THREAD != _owner) { 6 7 if (THREAD->is_lock_owned((address) _owner)) { 8 9 // Transmute _owner from a BasicLock pointer to a Thread address. 10 11 // We don't need to hold _mutex for this transition. 12 13 // Non-null to Non-null is safe as long as all readers can 14 15 // tolerate either flavor. 16 17 assert (_recursions == 0, "invariant") ; 18 19 _owner = THREAD ; 20 21 _recursions = 0 ; 22 23 OwnerIsThread = 1 ; 24 25 } else { 26 27 // NOTE: we need to handle unbalanced monitor enter/exit 28 29

ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS)

本小妞迷上赌 提交于 2019-12-04 04:13:43
1 // Wait/Notify/NotifyAll 2 3 // 4 5 // Note: a subset of changes to ObjectMonitor::wait() 6 7 // will need to be replicated in complete_exit above 8 9 void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) { 10 11 Thread * const Self = THREAD ; 12 13 assert(Self->is_Java_thread(), "Must be Java thread!"); 14 15 JavaThread *jt = (JavaThread *)THREAD; 16 17 18 DeferredInitialize () ; 19 20 21 // Throw IMSX or IEX. 22 23 CHECK_OWNER(); 24 25 26 EventJavaMonitorWait event; 27 28 29 // check for a pending interrupt 30 31 if (interruptible && Thread::is_interrupted(Self, true) && !HAS

How to see C++ stack trace for assert failure in Visual Studio 2012?

落花浮王杯 提交于 2019-12-04 03:58:31
问题 How can I see the stacktrace when my assert fails in visual studio 2012? If I am attahed to a process, it works as expected, but when I just build using F5 (debug), my assert happens, giving me the "Abort, Retry, Ignore" prompt, but I don't see my callstack in the debugger. Is there any way to enable it during debug builds, or will I always have to build and then attach to the process? My assert is just a simple assert(1 == 2) to get it to fail and see the callstack. 回答1: (Reposting from

Pytest实战Web测试框架

本小妞迷上赌 提交于 2019-12-04 03:32:44
https://www.jianshu.com/p/9a03984612c1?utm_campaign=hugo&utm_medium=reader_share&utm_content=note&utm_source=weixin-timeline&from=timeline&isappinstalled=0 项目结构 用例层(测试用例) | Fixtures层(业务流程) | PageObject层 | Utils实用方法层 使用pytest-selenium 基础使用 # test_baidu.py def test_baidu(selenium): selenium.get('https://www.baidu.com') selenium.find_element_by_id('kw').send_keys('简书 韩志超') selenium.find_element_by_id('su').click() 运行 $ pytest test_baidu.py --driver=chrome 或配置到pytest.ini中 [pytest] addopts = --driver=chrome 使用chrome options # conftest.py import pytest @pytest.fixture def chrome_options(chrome

Unit Test Assert.AreEqual failed

独自空忆成欢 提交于 2019-12-04 03:09:16
问题 I have a unit test for a method which gets an object from a collection. This keeps failing and I cannot see why, so I have created a very simple test below to create 2 supplier object and test they are equal to see if I can spot the problem in my test of my code. But this test again is failing. Can anyone see or explain why? [TestMethod()] public void GetSupplierTest2() { Supplier expected = new Supplier(); expected.SupplierID = 32532; expected.SupplierName = "Test 1" Supplier actual = new

How to use static_assert for constexpr function arguments in C++?

戏子无情 提交于 2019-12-04 03:07:32
问题 I have several brief constexpr functions in my libraries that perform some simple calculations. I use them both in run-time and compile-time contexts. I would like to perform some assertions in the body of these functions, however assert(...) is not valid in a constexpr function and static_assert(...) can not be used to check function parameters. Example: constexpr int getClamped(int mValue, int mMin, int mMax) noexcept { assert(mMin <= mMax); // does not compile! return mValue < mMin ? mMin

NUnit Nested Collection Comparison

大兔子大兔子 提交于 2019-12-04 02:41:53
Is there something similar to CollectionAssert.AreEquivalent() that works with nested collections? The following code... CollectionAssert.AreEquivalent ( new Dictionary<int, Dictionary<int, string>> { { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary < int, string > { { 20, "eggs" }, { 21, "eels" } } }, { 3, new Dictionary < int, string > { { 30, "hovercraft" } } } }, new Dictionary<int, Dictionary<int, string>> { { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary < int, string >

Multiple Asserts in a Unit Test [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-04 00:29:34
This question already has answers here : Closed 2 years ago . Is it bad practice to have more than one assertion in a unit test? [closed] (8 answers) I've just finished reading Roy Osherove's "The Art of Unit Testing" and I am trying to adhere to the best practices he lays out in the book. One of those best practices is to not use multiple asserts in a test method. The reason for this rule is fairly clear to me, but it makes me wonder... If I have a method like: public Foo MakeFoo(int x, int y, int z) { Foo f = new Foo(); f.X = x; f.Y = y; f.Z = z; return f; } Must I really write individual

使用xUnits来实现单元测试

你离开我真会死。 提交于 2019-12-04 00:22:00
目录 前言 单元测试 xUnit 小结 附录 前言 从开始敲代码到现在,不停地都是在喊着记得做测试,记得自测,测试人员打回来扣你money之类的,刚开始因为心疼钱(当然还是为了代码质量),就老老实实自己写完自己跑一遍,没有流程没有规划没有测试文档,就是自己整理一组数据跑一遍,最后依然还是让测试人员老老实实把一大堆测试问题扔给你。 单元测试 首先,还是来聊聊为啥要搞测试吧。 测试有助于代码整体健壮性,覆盖测试、压力测试都是为了全方位多角度更快更好为用户服务。 测试有助于提高程序猿的积极性以及引起自身的重视,毕竟一个坑栽一遍就够了,两次也能容忍,再三再四再五怕是要被搞,同时这也是自我提高的一种手段吧。 软件开发流程收尾的工作就是测试,绕不过,毕竟验收才是最终目标,达到效果才能获得应有的。 好了,聊完这些,当然我也不是专业测试人员,肯定不会给个测试文档模板,喏,照着这个规范起来,我主要是要鼓捣下我之前一直想试试的单元测试,这个自动化测试的手段之一,一直想试试但是一直都放着。 在 MSTest , NUnit , xUint 这三个中让我稍微犹豫了下,不过三七二十八管他呢,随便来个吧,就选了 xUnit ,当然MSTest是官方的,支持度应该高点儿,但是这不是我们该犹豫抉择的地方。 xUnit 首先,我们新建一个项目 April.Test 。 Fact 新建之后,我们看到有个默认的