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

  • Home
  • SEARCH
  • 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 65807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:00:16+00:00 2026-05-10T19:00:16+00:00

What is the best way to unit test a method that doesn’t return anything?

  • 0

What is the best way to unit test a method that doesn’t return anything? Specifically in c#.

What I am really trying to test is a method that takes a log file and parses it for specific strings. The strings are then inserted into a database. Nothing that hasn’t been done before but being VERY new to TDD I am wondering if it is possible to test this or is it something that doesn’t really get tested.

  • 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. 2026-05-10T19:00:16+00:00Added an answer on May 10, 2026 at 7:00 pm

    If a method doesn’t return anything, it’s either one of the following

    • imperative – You’re either asking the object to do something to itself.. e.g change state (without expecting any confirmation.. its assumed that it will be done)
    • informational – just notifying someone that something happened (without expecting action or response) respectively.

    Imperative methods – you can verify if the task was actually performed. Verify if state change actually took place. e.g.

    void DeductFromBalance( dAmount )  

    can be tested by verifying if the balance post this message is indeed less than the initial value by dAmount

    Informational methods – are rare as a member of the public interface of the object… hence not normally unit-tested. However if you must, You can verify if the handling to be done on a notification takes place. e.g.

    void OnAccountDebit( dAmount )  // emails account holder with info 

    can be tested by verifying if the email is being sent

    Post more details about your actual method and people will be able to answer better.
    Update: Your method is doing 2 things. I’d actually split it into two methods that can now be independently tested.

    string[] ExamineLogFileForX( string sFileName ); void InsertStringsIntoDatabase( string[] ); 

    String[] can be easily verified by providing the first method with a dummy file and expected strings. The second one is slightly tricky.. you can either use a Mock (google or search stackoverflow on mocking frameworks) to mimic the DB or hit the actual DB and verify if the strings were inserted in the right location. Check this thread for some good books… I’d recomment Pragmatic Unit Testing if you’re in a crunch.
    In the code it would be used like

    InsertStringsIntoDatabase( ExamineLogFileForX( 'c:\OMG.log' ) ); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I think this will become less of an issue now… May 11, 2026 at 10:48 am
  • added an answer You can't do that, unless you can change the assembly… May 11, 2026 at 10:48 am
  • added an answer You have to wrap the connection string instide an entity… May 11, 2026 at 10:48 am

Related Questions

What is the best way to unit test a method that doesn't return anything?
What is the best way to unit test a method that calls into multiple
What is the best way to verify/test that a text string is serialized to
What is the best way to authorize all users to one single page in
What is the best way to store international addresses in a database? Answer in
What is the best way to include an html entity in XSLT? <xsl:template match=/a/node>
What is the best way to iterate through a strongly-typed generic List in C#.NET
What is the best way to manage a list of windows (keeping them in
What is the best way to create redundant subversion repositories? I have a subversion
What is the best way to record statistics on the number of visitors visiting

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.