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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:28:30+00:00 2026-06-01T21:28:30+00:00

How to test this? public void TestMethod() { if(aDenpendency.someMethod()) return; // Followed by other

  • 0

How to test this?

public void TestMethod()
{
   if(aDenpendency.someMethod()) return;

   // Followed by other logic....
}

I don’t have another dependency in the following logic, so I couldn’t use AssertWasNotCalled.

Thanks in advance!!

  • 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-06-01T21:28:31+00:00Added an answer on June 1, 2026 at 9:28 pm

    It is a mistake to test as you are describing. And denotes poor code structure and is a definate code smell, you should refactor and unit test that code, Given that you aim to test it has not been called it follows you also want a test when it has been called.

    You need to have a method have a single responsibility,therefore for more sensible unit testing you can take out the logic after the return encase it in a method and unit test the output of that method.

    A unit test is not there to test what was not called it is there to either test an expectation setup by a mock/fake or you should test the result of the operation.

    You could write a test that tests the state of the object once the method has been called but this is really an integration test rather than a unit test. That means you can test the state that is as should be after the return statement has executed the other code will not have executed so whatever that modifies or processes will not have been modified.

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

Sidebar

Related Questions

I have a test in C# that looks like this: public void CanLog() {
I have this method: public void testJSNI2(){ String x = test; } I can
Someone can explain me why this test fails : [TestMethod] public void WierdComparison() {
I'm learning VS Unit test and tried this: [TestMethod()] public void calcTest() { double
I have a class defined by an interface public interface Test { void testMethod();
Given this test fixture: [TestClass] public class MSTestThreads { [TestMethod] public void Test1() {
I have the following unit test: [TestMethod] public void Add_Returns_Edit_View() { // Act ActionResult
Consider this unit test: [TestMethod] public void QueueManager_OnNextItem() { bool called = false; var
Consider this unit test code: [TestMethod] public void RunNotTest() { // 10101100 = 128
Shouldn't this test pass: [TestMethod] public void derived_message_subscription() { bool handled = false; Messenger.Default.Register<GenericMessage<baseClass>>(this,

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.