assert

RhinoMocks: AssertWasCalled doesn't work on Stub

狂风中的少年 提交于 2019-12-11 02:44:52
问题 I'm trying to assert with RhinoMocks that a certain property setter was called. But it's not working as expected. The following simplified example illustrates the problem. Consider this interface: public interface IMyInterface { string SomeProperty { get; set; } } And now consider the following code: var mock = MockRepository.GenerateStub<IMyInterface>(); mock.SomeProperty = "abc"; mock.AssertWasCalled(x => x.SomeProperty = Arg<string>.Is.Anything); I was expecting the assert on the last line

Asserts in Python 2.7 not working for me example assertIn

为君一笑 提交于 2019-12-11 00:18:14
问题 I have python 2.7 installed on my Mac. (verified by running python -v in terminal) When I try to use any of the new 2.7 assert methods I get AtributeError. I have looked at http://docs.python.org/2/library/unittest.html and can't find anything. The Asserts that come with 2.6 all work Ex Self.AssertEqual (x,x) Below is my code. When I call the assertIn I get the below message. * Test complete (ERROR): test012_Add_user2 (__main__.TestSuite) (<type 'exceptions.AttributeError'>, AttributeError("

Best practice for Python: assert command() == False [closed]

北慕城南 提交于 2019-12-10 23:28:08
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I wonder what is better/best: >>> def command(): ... return False ... >>> assert command() == False >>> assert command() is False >>>

assert_select first and second html table cell contents in rails

十年热恋 提交于 2019-12-10 21:45:36
问题 I have the following html table: <table class="list user_permission"> <tr> <th>Name</th> <th>Permission</th> </tr> <tr id="permission_1"> <td> test user01 </td> <td> Reading permission </td> </tr> </table> I want to assert in my tests the content of my first and second table cells. I tried it in the following way: assert_select "tr#permission_1 td", "test user01" assert_select "tr#permission_1 td", "Reading permission" But it didn't work, it couldn't find such a entry. 回答1: You could test

Python: After raising argparse.ArgumentError, argparse raises generic error

给你一囗甜甜゛ 提交于 2019-12-10 19:01:05
问题 I defined a custom regex type for an argument that needs to follow an exact format. I used code from another post (regex custom type) that has been super useful. My problem is that I'm writing unit tests where I expect the regex to fail and trying to assert that the argparse.ArgumentError is raised ( assertRaises(argparse.ArgumentError, parser.parse_args(inargs.split())) ). The problem is that argparse appears to be catching the ArgumentError and throwing a generic error, preventing me from

LinkedBlockingQueue与ArrayBlockingQueue

北城余情 提交于 2019-12-10 18:38:49
阻塞队列与普通的队列(LinkedList/ArrayList)相比,支持在向队列中添加元素时,队列的长度已满阻塞当前添加线程,直到队列未满或者等待超时;从队列中获取元素时,队列中元素为空 ,会将获取元素的线程阻塞,直到队列中存在元素 或者等待超时。 在JUC包中常用的阻塞队列包含ArrayBlockingQueue/LinkedBlockingQueue/LinkedBlockingDeque等,从结构来看都继承了AbstractQueue实现了BlockingQueue接口(LinkedBlockingDeque是双向阻塞队列,实现的是BlockingDeque接口),在BlockingQueue接口中定义了几个供子类实现的接口,可以分为3部分,puts操作、takes操作、其他操作。 puts操作 add(E e) : 添加成功返回true,失败抛IllegalStateException异常 offer(E e) : 成功返回 true,如果此队列已满,则返回 false(如果添加了时间参数,且队列已满也会阻塞) put(E e) :将元素插入此队列的尾部,如果该队列已满,则一直阻塞 takes操作 remove(Object o) :移除指定元素,成功返回true,失败返回false poll() : 获取并移除此队列的头元素,若队列为空,则返回 null

Assert uniqueness of fields in list

不想你离开。 提交于 2019-12-10 16:36:15
问题 I have made a list in C# and I want to make a test to see if all the values of the Id fields are unique. public static List<RestaurantReview> _reviews = new List<RestaurantReview> { new RestaurantReview { Id = 1, Name = "McDonalds", }, new RestaurantReview { Id = 2, Name = "Burger King", }, } Because I did some debugging I fount out that it is running trough the list but I do not get the proper test value. Could someone please explain what I am doing wrong here? [TestMethod()] public void

JavaSE-单元测试、反射、注解

旧城冷巷雨未停 提交于 2019-12-10 16:20:44
[TOC] 第一章:单元测试 1.1 测试分类 黑盒测试,不需要写代码,给输入值,看程序是否能够输出期望的值。 白盒测试,需要写代码的。关注程序具体的执行流程。 利用java中的junit依赖环境是白盒测试的一种方式 1.2 Junit的使用步骤 定义一个测试类(测试用例) 定义测试方法:可以独立运行 给方法加@Test 导入junit依赖环境 判定结果: 红色:失败 绿色:成功 一般我们会使用断言操作来处理结果 Assert.assertEquals(期望的结果,运算的结果) ; Before和After @Before: 修饰的方法会在测试方法之前被自动执行 @After: 修饰的方法会在测试方法执行之后自动被执行 1.3 Junit使用 程序代码 /* * 计算器类 * */ public class Calc { public int add(int num1,int num2){ return num1+num2; } public int subtract(int num1,int num2){ return num1-num2; } public int multi(int num1,int num2){ return num1*num2; } public int div(int num1,int num2){ return num1+num2; } } 测试代码

python assert fires with -O

吃可爱长大的小学妹 提交于 2019-12-10 15:57:16
问题 I am trying to make sure that an assert is not executed by python when using -O. My test program however indicates that it is always executed. I specifically use -O on the command line and I used -O when I ran setup.py with both build and install. Before I submit a bug report I wanted to make sure I did not do any rookie mistakes... So do I need to do something else or different so that the assert is not executed? My simple script: print __debug__ if __debug__: print "True branch" else: print

Hamcrest Matchers - Assert Type of List

点点圈 提交于 2019-12-10 14:39:30
问题 The Problem I'm currently trying to use Hamcrest Matchers to assert that the list type being returned is of a specific type. For example, let's say I have the following List that is being returned by my service call: List<SomePOJO> myList; I want to assert that the list being returned is parametrized of type SomePOJO and not TheOtherPOJO . However, it appears that Hamcrest Matchers does not have this sort of functionality. What I Have Tried After some research, I have seen the following