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 75k
  • Answers 75k
  • 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 Could the problem be that the .h file you are… May 11, 2026 at 2:46 pm
  • added an answer Great solution from MrJavaGuy but there is a typo in… May 11, 2026 at 2:46 pm
  • added an answer Maybe this site has the answer: How SharePoint communicates with… May 11, 2026 at 2:46 pm

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
I need to test a method belonging to a service class. This service class
I've decoupled events in this WPF application in the following way. What is the
I have encountered a strange Invalid Packet Lenght (that is how the error is

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.