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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:27:38+00:00 2026-05-26T15:27:38+00:00

When testing a method that is of return type bool. Should you have: expected

  • 0

When testing a method that is of return type bool.

Should you have:

expected = true;
Assert.AreEqual(expected, actual);

or

Assert.IsTrue(actual);

I know they both produce the same outcome, but which is better practise to use?

EDIT: For example, if I do AreEqual, is it not essentially the same as doing IsTrue on a method that returns a string a la below:

string expected = “true”;
string actual = test.testMethod(data)
bool test;

if expected.equals(actual)
    test = true;
else 
    test = false;
Assert.IsTrue(test);
  • 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-26T15:27:38+00:00Added an answer on May 26, 2026 at 3:27 pm

    You should only use Assert.IsTrue if you’re testing something which directly returns a boolean that should always be true.

    You should not massage data to get a boolean for IsTrue; instead, you should call a more relevant method in Assert or CollectionAssert.

    In your edited example, you should by all means call Assert.AreEqual instead; it will give you a much nicer message.

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

Sidebar

Related Questions

I am starting out with unit testing, I have a method that uses the
I'm wondering how to go about testing this. I have a method that takes
I'm having trouble unit testing a method that changes some properties of a reference
I've got a few methods that should call System.exit() on certain inputs. Unfortunately, testing
When I'm testing a void method there is nothing to assert.For example a CreateSomething
Edit #2: Does anyone have a good method of testing the middle of a
Should one create unit tests involving IO? Ie, testing a class method for serializing/deserializing
I have a group of test cases that all should have exactly the same
I have a simple class (for testing purposes) that I am trying to Query
I have the following repository that I use for unit testing: public class MyTestRepository<T>

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.