- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前有一组单元测试,它们对于许多 Rest API 端点都是一致的。假设类是这样定义的。
public abstract class GetAllRouteTests<TModel, TModule>
{
[Test]
public void HasModels_ReturnsPagedModel()
{
// Implemented test
}
}
实现的测试夹具如下所示:
[TestFixture(Category = "/api/route-to-test")]
public GetAllTheThings : GetAllRouteTests<TheThing, ModuleTheThings> { }
这使我能够在所有 GET all/list 路由上运行许多常见测试。这也意味着我有直接链接到被测试模块的类,以及 Resharper/Visual Studio/CI 中测试和代码之间的链接“正常工作”。
挑战在于一些路由需要查询参数来通过路由代码测试其他路径;
例如/api/route-to-test?category=大。
由于 [TestCaseSource] 需要静态字段、属性或方法,因此似乎没有很好的方法来覆盖要传递的查询字符串列表。我想出的最接近的东西似乎是一个黑客。即:
public abstract class GetAllRouteTests<TModel, TModule>
{
[TestCaseSource("StaticToDefineLater")]
public void HasModels_ReturnsPagedModel(dynamic args)
{
// Implemented test
}
}
[TestFixture(Category = "/api/route-to-test")]
public GetAllTheThings : GetAllRouteTests<TheThing, ModuleTheThings>
{
static IEnumerable<dynamic> StaticToDefineLater()
{
// yield return all the query things
}
}
这是有效的,因为静态方法是为已实现的测试类定义的,并由 NUnit 找到。巨大的骇客。对于使用抽象类的其他人来说也是有问题的,因为他们需要“知道”将“StaticToDefineLater”实现为静态的东西。
我正在寻找实现此目标的更好方法。似乎在 NUnit 3.x 中删除了非静态 TestCaseSource 源,所以就这样了。
提前致谢。
注意事项:
最佳答案
我解决类似问题的方法是使用一个实现 IEnumerable 的基源类(NUnit 的另一个可接受的源),考虑一下这个设计是否适合您的用例:
// in the parent fixture...
public abstract class TestCases : IEnumerable
{
protected abstract List<List<object>> Cases { get; }
public IEnumerator GetEnumerator()
{
return Cases.GetEnumerator();
}
}
// in tests
private class TestCasesForTestFoobar : TestCases
{
protected override List<List<object>> Cases => /* sets of args */
}
[TestCaseSource(typeof(TestCasesForTestFoobar))]
public void TestFoobar(List<object> args)
{
// implemented test
}
关于c# - NUnit 3.x - 后代测试类的 TestCaseSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45318698/
使用捆绑的 NUnit 工具配置了 NUnit 步骤,如下所示: 执行步骤后,我在日志开头出现以下消息时遇到困难: The TeamCity NUnit runner requires the fol
是否可以定义自定义过滤器,以便 NUnit 仅运行特定测试?我的许多 Nunit 测试都标有自定义属性“BugId”。是否可以编写一个过滤器,以便我可以传入一个数字并仅使用该属性和数字运行测试?如果是
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我想使用 NUnit 来运行 GUI/集成测试。我想做的是在所有测试之前初始化一些自定义报告(来 self 们使用的 GUI 测试框架),并在整个套件运行后运行报告导出。 是否有一些“ super ”
我需要从不同的单元调用测试以在我当前的单元中使用(我指的单元是类)。 NUnit 是否有基础设施可以做到这一点,还是我应该继续做我正在做的事情?实例化类并调用方法? 谢谢! 最佳答案 如果我没理解错的
我将 NUnit 与 CruiseControl.NET 一起使用。我有很多测试项目和程序集。当我运行测试时,在 NUnit 详细信息页面上,它只显示一个程序集,但包含来自所有程序集的所有测试。在日志
我有 13 个独立但相关的架构程序集,以及 13 个独立的 NUnit 测试程序集,每个测试程序集都包含与其匹配的架构程序集的所有测试装置。我正在使用 NUnit 2.5.2(当前最新版本)。 我可以
我可以强制每个 nunit 测试方法在单独的进程上运行吗?我需要这样做,因为调用一些被测方法可能会产生副作用。因此,我需要确保每个单元测试都与其他单元测试完全隔离运行。 最佳答案 您可以使用“/pro
我想在它们运行之前报告它们,并且可以选择通过 shell 脚本运行单个测试而无需管理类别。我们有一些非托管代码可能会使进程处于不良状态,有时很乐意在每次 nunit-console 运行时单独运行每个
我有一些初始化代码来使用我的 API。初始化可能会失败,我想在 NUnit 测试中对其进行测试。 初始化之后,可以使用 API。我也在测试 API,但我所有的测试方法都将使用相同的通用初始化代码。 我
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我已将我的测试配置为在发生故障时最多重试 x 次,以确保故障是合法的,而不是运行期间的侥幸。我没有在初始失败时记录错误消息。 但是,我注意到如果我正在运行测试,第一个测试会失败,然后第二个测试会通过,
由于不清楚的原因,我的 Nunit 测试装置不能在一次运行中执行,所以我被迫在单独的运行中执行一些测试。然而,这意味着测试结果被拆分到多个输出文件中。 是否有可以将 NUnit 结果 XML 文件合并
我创建了一个 NUnit 理论来帮助我测试一些代码。被测试的实际代码对于这个问题并不像我用来测试它的数据那么重要。即,24 小时制中的小时和分钟。 我以这种方式编写我的装置是为了利用这些特性并符合 N
如果我有以下代码: [TestFixture] public class MyBaseTest { protected ISessionManager _sessionManager;
我有一组单元测试,我需要从一个命令行调用中运行它们。其中一个程序集使用与其余程序集不同的配置文件。有没有办法在一个 nunit 项目文件中指定多个应用程序配置文件? 最佳答案 不在项目文件中,但您可以
我已经成功地为 TeamCity 服务器上的每个构建运行了 MSTest。 我有几个使用 NUnit 的项目,所以希望让 TeamCity 运行 NUnit 测试就像运行 MSTests 一样简单:
当我的夜间构建完成时,我会自动运行一些 NUnit 测试。我有一个控制台应用程序检测新构建,然后将构建的 MSI 复制到本地文件夹,并将我的所有组件部署到测试服务器。之后,我在 NUnit dll 中
有没有办法从 TeamCity 的“测试”选项卡中生成 NUnit 测试的可视化结果,目前我的 NAnt 脚本使用以下任务输出结果的 .xml 文件: TIA 最佳答案 可以使用 Te
我们使用 NUnit 来执行集成测试。这些测试非常耗时。通常,检测故障的唯一方法是超时。 我希望一旦检测到单个故障就停止执行测试。 有没有办法做到这一点? 最佳答案 使用 nunit-console,
我是一名优秀的程序员,十分优秀!