-1

I have this Method that I am testing, test if its just getting the data from database. Kinda looking for suggestions to maybe on my unit test below. I am still new on unit test.

[TestMethod()]
public void GetUnprocessedDataTest()
{
    using (var db =new ManualWithDrawDataContext())
    {
        var results = _test.GetUnprocessedData(db);
        Assert.AreEqual(true, results.Any());
    }
}

//Method to test
public IQueryable<CouncilRefundCase> GetUnprocessedData(ManualWithDrawDataContext db)
{
    var dataLCases = db.CouncilRefundCases.Where(x => x.ProcessStatusId == (int?)ProcessStatus.Unprocessed);
    return dataLCases;
}
croxy
  • 4,082
  • 9
  • 28
  • 46
Anele Ngqandu
  • 115
  • 1
  • 17
  • 4
    If it is getting data from an actual real database, it isn't a unit test. – mjwills Jun 13 '18 at 12:20
  • So you mean those are not the kind of methods to be tested? – Anele Ngqandu Jun 13 '18 at 12:23
  • I mean that it doesn't meet the usual definition of a unit test. It would instead be an integration test. https://stackoverflow.com/questions/1054989/why-not-hit-the-database-inside-unit-tests may be worth a read. – mjwills Jun 13 '18 at 12:25
  • Unit tests shouldn't depend on infraestructure. – Alpha75 Jun 13 '18 at 12:27
  • I see, ok cool thanks for the Info – Anele Ngqandu Jun 13 '18 at 12:29
  • Use In memory database for unit testing instead of testing against actual DB. – user1672994 Jun 13 '18 at 12:34
  • Why your data comes from database? Does it have some magic which cannot be solved by [xUnit and its test data providing features](http://hamidmosalla.com/2017/02/25/xunit-theory-working-with-inlinedata-memberdata-classdata/)? – AndrasCsanyi Jun 14 '18 at 12:26
  • @SayusiAndo I had that method in my code so I was just testing all the methods in the app. and that method is just fetching data from the database – Anele Ngqandu Jun 14 '18 at 12:34

1 Answers1

3

You should use a mocking framework to "fake" the database which you called during your tests. After that you will be able to check your methods performance with no dependency in any DB, that will make it a unit-test.