assert

人生苦短?试试Groovy进行单元测试

拥有回忆 提交于 2019-11-25 23:12:37
如果您今天正在编程,那么您很可能听说过单元测试或测试驱动的开发过程。我还没有遇到一个既没有听说过又没有听说过单元测试并不重要的程序员。在随意的讨论中,大多数程序员似乎认为单元测试非常重要。 但是,当我开始使用代码并问“单元测试在哪里?”时,我得到了一个完全不同的故事。我最近在网上问我的程序员朋友为什么不这样做,以及为什么其他程序员不这样做呢?不要编写单元测试。当我问程序员或IT经理同样的问题时,我经常听到的第一答案是:“我没有时间”或类似的问题。通常会出现这样的论点,即使用单元测试编写应用程序要比不使用单元测试编写时间长20%,并且“我们受到时间限制”。 我的建议–当我们尝试解决时间不足的问题时,也许我们可以在娱乐性上做出一些贡献。 在实践中 我正在为一个应用程序设计原型,该应用程序将允许用户输入有关房屋装修项目的信息,然后与朋友共享该项目的材料和工具信息。然后,朋友可以承诺贷款或购买项目中所需的一些材料或工具。基本上是用于家庭装修项目的“登记处”。 测试将在采用Project对象的方法上进行,遍历该项目的工具列表以查看该工具是否已经被承诺,并创建一个未被承诺的工具列表。然后,它将把该列表传递给将查询每个工具当前价格的服务。 原型是用Grails完成的,但是我们将用Java编写此方法: public List<Tool> neededToolList(Project project

智能合约编程语言-solidity快速入门(下)

时光毁灭记忆、已成空白 提交于 2019-11-25 22:57:10
上一篇: 智能合约编程语言-solidity快速入门(上) solidity区块及交易属性 在介绍区块及交易属性之前,我们需要先知道solidity中自带了一些全局变量和函数,这些变量和函数可以认为是solidity提供的API,这些 API 主要表现为Solidity 内置的特殊的变量及函数,它们存在于全局命名空间里,主要分为以下几类: 有关区块和交易的属性 ABI编码函数 有关错误处理 有关数学及加密功能 有关地址和合约 我们在编写智能合约的时候就可以通过这些API来获取区块和交易的属性(Block And Transaction Properties),简单来说这些API主要用来提供一些区块链当前的信息,下表列出常用的一些API: API 描述 blockhash(uint blockNumber) returns (bytes32) 返回给定区块号的哈希值,只支持最近256个区块,且不包含当前区块 block.coinbase (address) 获取当前块矿工的地址 block.difficulty (uint) 获取当前块的难度 block.gaslimit (uint) 获取当前块的gaslimit block.number (uint) 获取当前区块的块号 block.timestamp (uint) 获取当前块的Unix时间戳(从1970/1/1 00:00:00

netty使用EmbeddedChannel对channel的出入站进行单元测试

时间秒杀一切 提交于 2019-11-25 22:27:41
一种特殊的Channel实现----EmbeddedChannel,它是Netty专门为改进针对ChannelHandler的单元测试而提供的。 名称 职责 writeInbound 将入站消息写到EmbeddedChannel中。如果可以通过readInbound方法从EmbeddedChannel中读取数据,则返回true readInbound 从EmbeddedChannel中读取入站消息。任何返回东西都经过整个ChannelPipeline。如果没有任何可供读取的,则返回null writeOutbound 将出站消息写到EmbeddedChannel中,如果现在可以通过readOutbound从EmbeddedChannel中读取到东西,则返回true readOutbound 从EmbeddedChannel中读取出站消息。任何返回东西都经过整个ChannelPipeline。如果没有任何可供读取的,则返回null finish 将EmbeddedChannel标记为完成,如果有可读取的入站或出站数据,则返回true。这个方法还将会调用EmbeddedChannel上的close方法 测试入站消息 public class FixedLengthFrameDecoder extends ByteToMessageDecoder { private final int

How to automatically generate a stacktrace when my program crashes

喜夏-厌秋 提交于 2019-11-25 22:19:54
问题 I am working on Linux with the GCC compiler. When my C++ program crashes I would like it to automatically generate a stacktrace. My program is being run by many different users and it also runs on Linux, Windows and Macintosh (all versions are compiled using gcc ). I would like my program to be able to generate a stack trace when it crashes and the next time the user runs it, it will ask them if it is ok to send the stack trace to me so I can track down the problem. I can handle the sending

【转】Cstring 使用说明

扶醉桌前 提交于 2019-11-25 22:12:12
1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值;否则返回0。 说明:此成员函数用来测试一个CString 对象是否是空的。 示例: 下面的例子说明了如何使用CString::IsEmpty。 // CString::IsEmpty 示例 CString s; ASSERT( s.IsEmpty() ); 请参阅 CString::GetLength 2.CString::Left CString Left( int nCount ) const; throw( CMemoryException ); 返回值:返回的字符串是前nCount个字符。 示例: CString s( _T("abcdef") ); ASSERT( s.Left(2) == _T("ab") ); 3.CString::LoadString BOOL LoadString( UINT nID ); throw( CMemoryException ); 返回值:如果加载资源成功则返回非零值;否则返回0。 nID 一个Windows 字符串资源ID。 说明: 此成员函数用来读取一个由nID 标识的Windows 字符串资源,并放入一个已有CString 对象中。 示例: 下面的例子说明了如何使用CString:

How do you assert that a certain exception is thrown in JUnit 4 tests?

房东的猫 提交于 2019-11-25 21:55:07
问题 How can I use JUnit4 idiomatically to test that some code throws an exception? While I can certainly do something like this: @Test public void testFooThrowsIndexOutOfBoundsException() { boolean thrown = false; try { foo.doStuff(); } catch (IndexOutOfBoundsException e) { thrown = true; } assertTrue(thrown); } I recall that there is an annotation or an Assert.xyz or something that is far less kludgy and far more in-the-spirit of JUnit for these sorts of situations. 回答1: JUnit 4 has support for