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 7034807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:13:49+00:00 2026-05-28T01:13:49+00:00

This is my first attempt to do unit tests, so please be patient with

  • 0

This is my first attempt to do unit tests, so please be patient with me.
I’m still trying to unit test a library that converts lists of POCOs to ADO.Recordsets.

Right now, I’m trying to write a test that creates a List<Poco>, converts it into a Recordset (using the method I want to test) and then checks if they contain the same information (like, if Poco.Foo == RS.Foo, and so on…).

This is the POCO:

public class TestPoco
{
    public string StringValue { get; set; }
    public int Int32Value { get; set; }
    public bool BoolValue { get; set; }
}

…and this is the test so far (I’m using xUnit.net):

[Fact]
public void TheTest()
{
    var input = new List<TestPoco>();
    input.Add(new TestPoco { BoolValue = true, Int32Value = 1, StringValue = "foo" });

    var actual = input.ToRecordset();

    Assert.Equal(actual.BoolValue, true);
    Assert.Equal(actual.Int32Value, 1);
    Assert.Equal(actual.StringValue, "foo");
}

What I don’t like about this are the three asserts at the end, one per property of the POCO.
I’ve read lots of times that multiple asserts in one test are evil (and I understand the reasons why, and I agree).

The problem is, how can I get rid of them?

I have Roy Osherove’s excellent book “The Art of Unit Testing” right in front of me, and he has an example which covers exactly this (for those who have the book: chapter 7.2.6, page 202/203):

In his example, the method under test returns an AnalyzedOutput object with several properties, and he wants to assert all the properties to check if each one contains the expected value.

The solution in this case:
Create another AnalyzedOutput instance, fill it with the expected values and assert if it’s equal to the one returned by the method under test (and override Equals() to be able to do this).

But I think I can’t do this in my case, because the method that I want to test returns an ADODB.Recordset.

And in order to create another Recordset with the expected values, I would first need to create it completely from scratch:

// this probably doesn't actually compile, the actual conversion method 
// doesn't exist yet and this is just to show the idea

var expected = new ADODB.RecordsetClass();
expected.Fields.Append("BoolValue", ADODB.DataTypeEnum.adBoolean);
expected.Fields.Append("Int32Value", ADODB.DataTypeEnum.adInteger);
expected.Fields.Append("StringValue", ADODB.DataTypeEnum.adVarWChar);

expected.AddNew();
expected.BoolValue = true;
expected.Int32Value = 1;
expected.StringValue = "foo";
expected.Update();

I don’t like this either, because this is basically a duplication of some of the code in the actual conversion method (the method under test), which is another thing to avoid in tests.

So…what can I do now?
Is this level of duplication still acceptable in this special situation, or is there a better way how to test this?

  • 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-28T01:13:49+00:00Added an answer on May 28, 2026 at 1:13 am

    I’d argue that in the spirit of the thing, this is fine. The reason that multiple asserts are “evil”, if I recall correctly, is that it implies that you are testing multiple things in one test. In this case, you are indeed doing that in that you are testing each field, presumably to make sure this works for several different types. Since that’s all an object equality test would do anyway, I think you are in the clear.

    If you really wanted to be militant about it, write one test per property (j/k!)

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

Sidebar

Related Questions

Because this is my first attempt at an extension method that seems quite useful
This is my first attempt at writing a QT app, and I'm just trying
I'm new to unit tests for my own projects, so this is my first
this if my first attempt at using streaming for WCF, and I am struggling
This is pretty strange (admitedly, this is my first attempt with python / sqlite),
I'm writing an application using DDD techniques. This is my first attempt at a
First attempt to use this cool site - after searching for 2 hours: So
To preface, this is my first attempt at MVVM... I buy it, I'm just
hi this is my first attempt at JavaScript: the following function is used to
First of all, this is my first attempt at a silverlight app and it'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.