Reusing NSpec specifications

白昼怎懂夜的黑 提交于 2020-01-05 09:35:54

问题


I've started with NSpec recently and now I'm not sure how to scale this.

What is the best way to reuse specifications (it["something"] = () => {};)?

Let's say I have an interface IMyService and 2 classes that implement it: Service1 and Service2.

Now I want to write specifications that apply at IMyservice level, and run them against my 2 implementation classes.

Maybe I'm missing something here, but I can find a simple way to do this.


回答1:


You can use a abstract class to reuse the specification. Here is an example:

/*
Output:

describe Service1
  it should do this
  it should also do this
  specify something unique to service1    
describe Service2
  it should do this
  it should also do this
  specify something unique to service2
*/


abstract class some_shared_spec : nspec
{
    public IMyservice service;

    void it_should_do_this()
    {

    }

    void it_should_also_do_this()
    {

    }
}

class describe_Service1 : some_shared_spec 
{
    void before_each()
    {
        service = new Service1();
    }

    void specify_something_unique_to_service1()
    {
    }
}

class describe_Service2 : some_shared_spec 
{
    void before_each()
    {
        service = new Service2();
    }

    void specify_something_unique_to_service2()
    {
    }
}



来源:https://stackoverflow.com/questions/10053168/reusing-nspec-specifications

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!