简体   繁体   English

存储有关测试方法的信息的最佳方式

[英]Best way to store information about a test method

I test some hardware products which have different configuration.我测试了一些具有不同配置的硬件产品。 I have a test method, which loops over all test cases for all products.我有一个测试方法,它循环所有产品的所有测试用例。 Since some products don't support functionalities, some cases should not be tested.由于某些产品不支持功能,因此不应测试某些情况。

What would be the best way to make the test method more dynamic?使测试方法更具动态性的最佳方法是什么? I was thinking of using a xml file where I would define, which steps should be executed for which product.我正在考虑使用一个 xml 文件来定义,应该为哪个产品执行哪些步骤。 Something like:就像是:

<products>
<product>
    <id>1</id>
    <steps>
        <step id="1" desc="Description1" />
        <step id="2" desc="Description2" />
        <step id="3" desc="Description3" />
<product>
<product>
    <id>2</id>
    <steps>
        <step id="1" desc="Description1" />
        <step id="3" desc="Description3" />
<product>

Take a look at Moq : you can easily setup some testable scenarios, like:看看Moq :您可以轻松设置一些可测试的场景,例如:

var mock = new Mock<ILoveThisFramework>();

// WOW! No record/replay weirdness?! :)
mock.Setup(framework => framework.DownloadExists("2.0.0.0"))
    .Returns(true);

// Hand mock.Object as a collaborator and exercise it, 
// like calling methods on it...
ILoveThisFramework lovable = mock.Object;
bool download = lovable.DownloadExists("2.0.0.0");

// Verify that the given method was indeed called with the expected value at most once
mock.Verify(framework => framework.DownloadExists("2.0.0.0"), Times.AtMostOnce());

I also like to use it together with FluentAssertions , for the flexibility of assertions and you can basically read the test, in a (almost) natural language, like:我也喜欢将它与FluentAssertions一起使用,以获得断言的灵活性,您基本上可以用(几乎)自然语言阅读测试,例如:

string actual = "ABCDEFGHI";
actual.Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);

The examples are from theirs respective home pages.这些示例来自他们各自的主页。

XML could be ok, but you could use SQLite and a custom configurator or simply a SQLite editor. XML 可以,但您可以使用 SQLite 和自定义配置器或简单的 SQLite 编辑器。

Because if you got to configure and make changes on your configuration, as soon as it get bigger and bigger a solution like SQL would allow you to perform changes in your configuration way better.因为如果您必须配置并更改您的配置,一旦它变得越来越大,像 SQL 这样的解决方案将允许您更好地执行配置更改。

If you think your configuration schema will vary from time to time maybe you could explore other noSQL options but they're not so portable as SQLite.如果您认为您的配置架构会不时变化,也许您可​​以探索其他 noSQL 选项,但它们不像 SQLite 那样可移植。

I can tell from my experience working in a product which components are configurable with xml files, that as soon as you grow and your xml files got fatter, they start to be a problem.我可以从我在产品中工作的经验看出哪些组件可以使用 xml 文件进行配置,一旦您成长并且您的 xml 文件变得越来越胖,它们就会开始成为一个问题。 Also updating the configuration in multiple places through regex its not cool.还通过正则表达式更新多个地方的配置,这并不酷。 We're now looking forward to migrate to a SQLite like solution.我们现在期待迁移到类似 SQLite 的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM