- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我关于 stackoverflow 的第一个问题,我希望这不是一个愚蠢的问题。 :)
基本上我所有的数据驱动测试都是这样的:
[TestMethod]
[DataSource(TestsDataSource)]
public void Test_With_Some_Fancy_Name()
{
if (myIsThisTestIgnored) return;
...
DataSource 属性 + app.config 连接字符串 + excel odbc 驱动程序 = excel 数据驱动测试。
myIsThisTestIgnored
在 [TestInitialize]
方法中设置(对于每个数据行,都有一个单独的测试和单独的 [TestInitialize]
),通过TestContext.DataRow["Ignore"]
,因此我可以通过 Excel 工作表中的一些 true/false 来“忽略”测试。
现在我的问题是:只要从测试方法返回就可以让测试通过。如何不让被忽略的测试在 MSTEST 测试运行器(以及通过 msbuild 的 CI 中)“通过”,或者更好的是,根本不显示它们?
在我们的 Ci Build 上,它总结了每个被忽略的(也就是通过的)测试,因为测试的计数是测试方法的 datarows x number
,给人一种运行的测试数量的错误印象。但是,直到现在,我发现没有办法以编程方式将测试结果设置为“已忽略”(或除“通过”/“失败”之外的任何其他状态)。
此外,在每个测试中去掉这个烦人的忽略行并增强断言消息而不用将每个断言包装在某个函数中也会很好。
因此,我认为最好/唯一的方法是 AOP 样式编程和使用自定义属性。我发现了这篇关于使用自定义属性增强您的 mstest 代码的旧帖子,值得一读:http://callumhibbert.blogspot.com/2008/01/extending-mstest.html
特别是链接文章中的最后一条评论让我开始思考,因为这个人不仅通过展示如何访问所有测试状态数据到属性(MarshalObject 的东西)让我开心,而且他以某种方式让它工作,引用他的话“以这种方式,我可以根据来自文本上下文(使用 DataSource 属性)和我创建的新自定义属性的数据驱动信息矩阵来确定是否运行测试。” . 是的..但是怎么做呢?
我拿了一些代码并实现了它,看起来像这样:
public class MyCustomAspect : TestAspect<MyCustomAttribute>, IMessageSink, ITestAspect
{ ....
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public IMessage SyncProcessMessage(IMessage msg)
{
....
// see last comment in linked article to how to get this MarshalObject
MyTestsClass testClass = (MyTestsClass)MarshalObject;
if(testClass.myTestInitializeRan && testClass.myIsThisTestIgnored)
{
// what to do here? I would like to get rid of the SyncProcessMessage invocation, but...
// return msg or null -> Exception "The method was called with a Message of an unexpected type."
// constructing a IMessage in an easy way (specifically CallMessage) seems not possible, and I have no clue how to construct a valid CallMessage that says "ignore test!"
}
else
{
IMessage message = _nextSink.SyncProcessMessage(msg);
return message;
}
同样:我想抑制这个数据行的测试运行,或者以某种方式将测试结果设置为“忽略”/“未知”。
对返回的 message
或 msg
做任何事情似乎毫无意义,因为 IMessage
接口(interface)只公开了 Properties
字典里面只有一些 MethodName 和东西,看起来没什么有趣的。
将 IMessage
转换为具体实现是行不通的:它们都是 System.Runtime 内部的。尽管可以强制转换为 ResultMessage 并在引发异常时返回 != null(因此您可以获取异常消息并通过新的 throw 调整错误消息)。
有什么想法吗?非常感谢您到目前为止的阅读。 ;)
最佳答案
How to not let the ignored tests "pass" in the MSTEST testrunner (and in the CI via msbuild), or even better, do not show them at all?
如果您不希望将跳过的测试视为已通过,则可以使用 Assert.Fail 或 Assert.Inconclusive 而不是简单地从测试用例返回。
您还可以找到 Data driven tests with test attributes in MSTest有用。作者展示了如何使用 postsharp 创建参数化 Row 测试,以跳过使用 excel 进行数据驱动测试的需要,而是将参数作为属性发布在测试方法之上。因此,当您想要删除或忽略一个测试用例时,您只需注释掉该数据行,它就不会显示了。
关于c# - MsTest 数据驱动 : ignore specific datarows via testattribute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6588078/
我正在尝试为基于 arm 的板交叉编译驱动程序。在 make 文件中,包含文件的搜索路径是主机内核的路径,即它指向 ubuntu 附带的 linux 头文件。我在主机系统(i7/ubuntu)上也有目
1、准备材料 开发板(正点原子stm32f407探索者开发板V2.4) 。 STM32CubeMX软件(Version 6.10.0) 。 野火DAP仿真器 。 keil µVis
是否可以通过 c# 应用程序“驱动”excel(即从 excel gui 下拉列表中选择某些内容,按下按钮并读取特定单元格的内容)? 这并不是真正用于测试,而是用于类似于 selenium 的数据报废
给定任何具有超过 5 个 View 和 View 模型的中间 MVVM 应用程序,是否有任何推荐的设计模式来说明如何为此类应用程序搭建脚手架? 现在我通常有一个在 App.OnStartup 中创建的
我想知道如何使用曼哈顿距离启发式来驱动 NxN 二维数组中的搜索。我有以下曼哈顿距离: private int manhattan(int[] pos, int tile) { int
我试图了解 CUmodule 在 CUDA 驱动程序 API 函数中实际上代表什么。 许多 CUDA 驱动程序 API 函数都有一个 CUmodule 句柄,但它是什么?它是引导驱动程序调用过程的 d
我正在尝试创建一个 java 程序,它将创建 excel 文件并将其上传到谷歌驱动器中。上传后我需要它来授予权限。我已经完成了所有这些,但问题在于尝试将 excel 文件转换为 google 文件,以
我正在拼命尝试从 Linux(Raspbian 内核 4.4.12-v7+)与使用 TIUSB3410 USB 部件的设备进行通信。 这是 dmesg 的输出: [ 2730.016013] usb
我有一个关于在 PCIe 上使用突发读写的问题。我有一个 fpga,它通过 PCIe 连接到 cpu。我有一个简单的驱动程序,仅用于测试。驱动程序向 FPGA 写入数据以及从 FPGA 读取数据。 f
我有大约 500 条通往特定页面的可能路径,我需要测试所有这些路径。该页面的每个路径看起来都类似于此(使用 PHP 网络驱动程序;通常有大约 10 个步骤): // Navigate to form
如果chrome驱动的版本和当前的chrome版本不同,我想写一个python代码,下载并运行与当前chrome版本匹配的chrome驱动。 这就是我一直在寻找的东西 driver = webdriv
我在 Centos 7 Linux 机器上尝试通过 pyodbc 连接到 SQL 数据库。我了解到您需要设置 DSN,您可以通过安装 freetds 驱动程序并执行以下操作来实现: import py
是否可以使用 NUnit 通过 NDepend 运行 CQL 查询?如果能够将 NDepend dll 包含在 UnitTests 库中并编写如下测试,那就太好了: [Test] public voi
我在 cassandra 中有巨大的表,超过 20 亿行并且还在增加。这些行有一个日期字段,它遵循日期桶模式以限制每一行。 即便如此,对于某个特定日期,我也有超过一百万条条目。 我想尽快读取和处理每一
考虑以下示例,其中一个模块的输出 (inner::out) 应该驱动两个输出(outer::out 和 outer::out2) 的上层层次: #include SC_MODULE(inner) {
我不确定是否可以有一个具有多个 MySQL 根的连接器。当我尝试只使用一根根时,它效果完美。我的有 2 个根的代码如下所示: [ 'locale' => 'es_ES.UTF-8',
我的桌面APP无法注册Mysql JDBC驱动 我下载mysql-connector-java-5.1.16.zip 解压mysql-connector-java-5.1.16-bin.jar并将其放
我有一个无限循环等待输入的 python 脚本,然后输入发生时做一些事情。我的问题是制作 python告诉 emacs 做某事。我只需要一些方法来发送 emacs 输入并让 emacs 评估该输入。
我最初问的没有明确说明我的问题/问题,所以我会更好地解释它。我有一个将 JDialog 设置为可见的 JButton。 JDialog 有一个 WindowListener 将其设置为在 window
假设“doc”是我想插入到 MongoDB 集合中的一些文档,而“collection”是我要将文档插入到的集合。 我有如下内容: try { WriteConcern wc = new Wr
我是一名优秀的程序员,十分优秀!