Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6833713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:00:45+00:00 2026-05-26T23:00:45+00:00

Firstly, forgive my use of the term unit when perhaps I mean integration test.

  • 0

Firstly, forgive my use of the term “unit” when perhaps I mean integration test. However, in this case I am treating testing of a DAO method as a unit and am not attempting to mock the underlining database.

I’ve been trying to test a particular DAO method that searches for particular entities –

public Factor GetMatchingFactor(int aircraftStoresConfigurationId, int stationId, DateTime timeStamp)
{
    // code etc....
}

No, normally, I try to have several unit tests, maybe a few for each parameter to ensure each is treated appropriately. I’m happy with this normally when the method itself processes the parameter, and at worse calls a dependent that I can test using mocks / stubs. However, in this particular method, the result of the method is not a pure function or one parameter, but rather a function of the parameters AND the test data.

Therefore, I struggle to define tests like

public void TestThatAircraftStoresConfigurationIdParameterIsApplied
public void TestThatStationIdParameterIsApplied
public void TestThatTimeStampParameterIsApplied

as their names are incorrectly, each does not just test one thing.

This also means that I’m struggling to follow the rule of only one Assert per test.

Therefore, I’ve tested this method using the following code with the same coverage, and possibly more meaningful.

    [Test]
    public void TestReturnsCorrectResult()
    {
        Assert.That(_sut.GetMatchingFactor(10001, Station.Station9Id,  new DateTime(2011, 11, 16, 10, 00, 00)).Id, Is.EqualTo(1), "Test 1");
        Assert.That(_sut.GetMatchingFactor(10001, Station.Station9Id,  new DateTime(2011, 11, 16, 11, 00, 00)).Id, Is.EqualTo(1), "Test 2");
        Assert.That(_sut.GetMatchingFactor(10001, Station.Station9Id,  new DateTime(2011, 11, 16, 19, 00, 00)).Id, Is.EqualTo(1), "Test 3");
        Assert.That(_sut.GetMatchingFactor(10001, Station.Station9Id,  new DateTime(2011, 11, 16, 19, 00, 01)).Id, Is.EqualTo(2), "Test 4");
        Assert.That(_sut.GetMatchingFactor(10001, Station.Station9Id,  new DateTime(2011, 11, 16, 19, 00, 02)).Id, Is.EqualTo(2), "Test 5");
        Assert.That(_sut.GetMatchingFactor(10001, Station.Station9Id,  new DateTime(2011, 11, 16, 14, 00, 00)).Id, Is.EqualTo(1), "Test 6");
        Assert.That(_sut.GetMatchingFactor(10001, Station.Station10Id, new DateTime(2011, 11, 16, 14, 00, 00)).Id, Is.EqualTo(1), "Test 7");
        Assert.That(_sut.GetMatchingFactor(10002, Station.Station11Id, new DateTime(2011, 11, 16, 14, 00, 00)).Id, Is.EqualTo(3), "Test 8");
        Assert.That(_sut.GetMatchingFactor(10002, Station.Station12Id, new DateTime(2011, 11, 16, 14, 00, 00)).Id, Is.EqualTo(3), "Test 9");
    }

I’m not comfortable with the multiple asserts, but it seems the only logical way to structure these tests. Can anyone suggest a better option?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:00:46+00:00Added an answer on May 26, 2026 at 11:00 pm

    This seems like a perfect fit for TestCases in NUnit 2.5. You could rewrite your code as follows:

    [TestCase(10001, Station.Station9Id,   2011, 11, 16, 10, 00, 00,  1)]
    [TestCase(10001, Station.Station9Id,   2011, 11, 16, 11, 00, 00,  1)]
    [TestCase(10001, Station.Station9Id,   2011, 11, 16, 19, 00, 00,  1)]
    [TestCase(10001, Station.Station9Id,   2011, 11, 16, 19, 00, 01,  2)]
    [TestCase(10001, Station.Station9Id,   2011, 11, 16, 19, 00, 02,  2)]
    [TestCase(10001, Station.Station9Id,   2011, 11, 16, 14, 00, 00,  1)]
    [TestCase(10001, Station.Station10Id,  2011, 11, 16, 14, 00, 00,  1)]
    [TestCase(10002, Station.Station11Id,  2011, 11, 16, 14, 00, 00,  3)]
    [TestCase(10002, Station.Station12Id,  2011, 11, 16, 14, 00, 00,  3)]
    public void TestReturnsCorrectResult(int configId, int stationId, int yy, int mm, int dd, int h, int m, int s, int expectedResult)
    {
        Assert.That(_sut.GetMatchingFactor(configId, stationId, new DateTime(yy,mm,dd,h,m,s)).Id, Is.EqualTo(expectedResult));
    }
    

    Now there’s only one assertion, but there are multiple things being tested. It’s really nice for integration tests like the one you’re describing.

    Note that you can only pass constants through the TestCase attribute, so you won’t be able to new up a DateTime object. Instead, you have have to pass the year, month, day, etc. as parameters to the method and then instantiate the DateTime yourself.

    You might also consider using some T4 script to generate your TestCase attributes from some other data – such as a CSV file. I’ve used this approach in the past with quite a bit of succcess and it allows end users to create test cases in Excel and then pass them to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

everyone. Firstly, forgive my poor English #_# I use ubuntu 11.10 now. And I
Firstly, please forgive me if I have asked this before (i suffer memory problems
Firstly I'm very new to web development so forgive me if this is a
firstly, pardon my pseudo-code, i think in this case it is more legible than
Firstly, I'm new to Python, Qt and PySide so forgive me if this question
Firstly, Real World Haskell , which I am reading, says to never use foldl
Firstly: I am totally a newbie for this kind of work. I have a
Firstly, I do not have any malicious intent out of this question. I would
Firstly, I'm not using rails. This is vanilla ruby application. I've read about packaging
Firstly is it possible to use objective C to find out if the user's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.