Avatar of satmisha
satmishaFlag for India

asked on 

How to test methos returns nothing in nUnit

Hi Team,

I have the following method which returns nothing and takes nothing, I need to write the test method using the NUnit framework in C#. How could I achieve that?

Public Async Task ReceiveDataOnQueue()
{
   Try
   {
      If(Dev)
         {
            cred = GenerateToken();
            sqlClient = new AmazonSQlClient(cred, endPoint);
         }
   else{
         
       sqlClient = new AmazonSQlClient(cred, endPoint)
      }
   
   ReadMessageFromQueue(sqlClient);
   DeleteMessageFromQueue();

   }
   Catch(Exception Ex)
   {
      Throw Ex
   }
}

Open in new window


Nishant
* .netcore* nunitC#

Avatar of undefined
Last Comment
satmisha
Avatar of ste5an
ste5an
Flag of Germany image

A method like this does not needed to be tested. Cause it only contains side-effects.

Maybe you rephrase your question and explain what you like test for what reason.

Also your method contains some smells, I would even say anti-patterns. You should view The Clean Code Talks - "Global State and Singletons" and "The Clean Code Talks -- Unit Testing".
Avatar of satmisha
satmisha
Flag of India image

ASKER

Thank you ste5an for your prompt reply.

I am totally novice to testing got stuck on this. What I need to write is a nUnit test case for the above-said method, there any many more but if I get the help on one probably I can start writing others.

Appreciate it if you could help me out with some link through which I can start with it.

Avatar of satmisha
satmisha
Flag of India image

ASKER

experts pls help...
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of satmisha
satmisha
Flag of India image

ASKER

thank you, ste5an.
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo