vendredi 20 novembre 2015

Unit Testing with Rhino Mocks

I have the following method called Execute() from the Abstract class called AutoLetterGenBatch in my ConsoleApp. I am trying to unit test this.

    public void Execute()
    {
        BatchJobSecurity.Instance.CreatePrincipal();

        DoExecute();
    }

So I set up what I believe are all the proper references and try to invoke the method like below .

[TestMethod]
    public void TestMethod1()
    {

        AutoLetterGenBatchJob ALGBJ = new AutoLetterGenBatchJob();
        ALGBJ.Execute();
    }

However, when I go to do the build it gives me this compilation error Error 34 Cannot create an instance of the abstract class or interface 'AutoLetterGenBatch.AutoLetterGenBatchJob' .

I am somewhat new to unit testing. I realize this probably isn't much of a test but I just want to see my Execute() method get hit for the time being. I have read that a good way to get around this problem with abstract classes is to set up a mock object for the abstract class. So I try to do this with RhinoMocks.

  [TestMethod]
    public void TestMethod1()
    {



        AutoLetterGenBatchJob ALGBJ = MockRepository.GenerateStub<AutoLetterGenBatchJob>();
        ALGBJ.Execute();




    }

It now builds with all of the proper using statements in place. However when the test runs I now get this error. Can't find a constructor with matching arguments . Again I am pretty new to this. If someone can help me to understand what it is I need to do it would be appreciated.

-Jason

Aucun commentaire:

Enregistrer un commentaire