English 中文(简体)
我如何告诉test子测试,以忽视基类测试,而不是子类测试?
原标题:How do I tell mstest to ignore tests in a base class but not in subclasses?

我有一个正由我工作的航标,这一航海标有<条码>I式记录仪/代码>接口,其中界定了任何记录储存发动机的基础方法(记忆中,数据库等)。 想法是,开发商和用户可以通过MEF原始接口添加或移除原木储存发动机。

但是,为了确认<代码>I CarloStore 执行可以正确储存、过滤和检索记录条目。 我为单位/一体化/一体化测试建立了基级:

public class LogStoreBaseTests
{
    protected ILogStore _store;

    [TestMethod]
    public void Can_Store_And_Retrieve_Records() { }

    [TestMethod]
    public void Can_Filter_Records_By_Inclusive_Text() { }

    [TestMethod]
    public void Can_Filter_Records_By_Exclusive_Text() { }

    // etc...
}

我通过做像:

[TestClass]
public class InMemoryLogStoreTests : LogStoreBaseTests
{
    [TestInitialize]
    public void Setup()
    {
        _store = new InMemoryLogStore();
    }
}

这样做是有好处的,但试验女士注意到,基类中的方法有<条码>[Method],但是由于舱面有<条码>的差错,因此没有自动进行有效测试。

我怎么能够告诉她,如果不从子类中操作,那么如何忽视方法?

最佳回答

退出管理系统的试样有<代码>[Ignore]。 人均 我把这一句和<代码>[《试验守则》]归根于我的基测验,它正确地忽视了基础测验的测试方法,同时在分级运行时使用基测方法。

问题回答

不能确定你是否能够告诉管理事务测试忽略某些测试,但你可以要求它不要操作某些测试类别。

例如,以下属性将测试列入一体化类别

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    public class IntegrationTestAttribute : TestCategoryBaseAttribute
    {
        public IList<string> categories;

        public IntegrationTestAttribute()
        {
            this.categories = new List<String> { "Integration" };
        }

        public override IList<string> TestCategories
        {
            get
            {
                return this.categories;
            }
        }
    }

另一种做法是,你可以把基类作为抽象的标志,使你的测试采用某些抽象的方法,这样,任何执行本类的人都会采用这些方法。

例如

[TestClass]
public abstract class BaseUnitTest
{
    public BaseUnitTest(){}
    private TestContext testContextInstance;        
    public TestContext TestContext
    {
        get
        {
            return testContextInstance;
        }
        set
        {
            testContextInstance = value;
        }
    }        
    [TestMethod]
    public void can_run_this_test_for_each_derived_class()
    {
        Assert.IsNotNull(this.ReturnMeSomething());
    }
    protected abstract string ReturnMeSomething();
}

[TestClass]
public class Derived1 : BaseUnitTest
{

    protected override string ReturnMeSomething()
    {
        return "test1";
    }
}

[TestClass]
public class Derived2 : BaseUnitTest
{
    protected override string ReturnMeSomething()
    {
        return null;
    }
}

另一种做法是使用AOP,如“管理试验扩展”,可找到“here

一种检验方法在相互继承时从未见过。 我建议考虑另一种做法,而不是围绕这种测试基础设施开展工作。

考虑:

  1. Move all tests in a single class marked by [TestClass] OR
  2. Create two completely separate test classed so they will not be coupled and affect each other




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签