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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:50:17+00:00 2026-05-13T00:50:17+00:00

If that title did not make sense (which I’m expecting =)) here is what

  • 0

If that title did not make sense (which I’m expecting =)) here is what I’m asking:

I have a function called ParseFile(). It takes a string as parameter, and a DataTable as a return value.

I want to unit-test this function. Is it wrong of me to code the function first, run it, take the output, serialize it to XML, save it as expected output, then write my unit-test to call the function and assert against that deserialized data?

I realize this helps me down the road, in cases where we get new input we might not have seen before and have to change the parsing function to handle it – running my test will now assert that I have not broken any currently working files. Awesome…

.. but in this case, the format will never change and is standard. So is it completely useless to do what I’m saying? And if it is, how to test this function then?

And heck, if what I’m saying is still a good idea – how would you even do that true TDD style and write the test first? Without tediously writing Assert calls() for every single expected field in a file? I’m not quite in full TDD ‘mode’ yet – but I’m trying to get there… and it’s cases like these I sometimes wonder how you write a test for it first possibly, when the expected output is a dataset for example…

Thanks

  • 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-13T00:50:17+00:00Added an answer on May 13, 2026 at 12:50 am

    It’s not wrong, but it’s not TDD.

    That being said, I’d like to warn you about asserting on XML strings: when something goes wrong when the XML size is large enough, you end up comparing the two XML strings manually, err well, visually.

    Been there, done that. I remember being in that situation, copying the XML in two files, modifying it to have one attribute per line and comparing the two files with diff. I said I’ll try to assert on the XML with XPath and/or XQuery next time.

    Also, isn’t your function doing too many things: parsing the string and generating the XML ? You might want to consider to separate this out.

    How would you even do that true TDD
    style and write the test first?

    If you really want to use TDD and keep one function, then you can start with a test: what should your XML output looks like with an empty string? This is your first test. Once it is pass, restart with a string with a simple element, write the test, make it pass, and take a more complex string. Lather, rinse, repeat.

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

Sidebar

Related Questions

ok, the title did not make much sense but this is what i am
That title is presumably awfully worded. I have some PostgreSQL tables. There is a
I'm not sure that title is worded very well, but not sure how else
I'm not sure that title conveys my meaning, please change it if you can
First of all, sorry about that title. I'm not the best at writing those
(I realize that my title is poor. If after reading the question you have
The title is not clear so let me explain: In my apps, I have
Not sure if that was the best Title in the world but I hope
As the title says, I want to have a build tool that quite much
Hope the title is not that confusing - honestly said I had no idea

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.