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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:29:32+00:00 2026-05-30T02:29:32+00:00

Why is it that every unit testing framework (that I know of) requires the

  • 0

Why is it that every unit testing framework (that I know of) requires the expected value in equality tests to always be the first argument:

Assert.AreEqual(42, Util.GetAnswerToLifeTheUniverseAndEverything());

assertEquals(42, Util.GetAnswerToLifeTheUniverseAndEverything());

etc.

I’m quite used to it now, but every coder I try to teach unit testing makes the mistake of reversing the arguments, which I understand perfectly. Google didn’t help, maybe one of the hard-core unit-testers here knows the answer?

  • 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-30T02:29:34+00:00Added an answer on May 30, 2026 at 2:29 am

    It seems that most early frameworks used expected before actual (for some unknown reason though, dice roll perhaps?). Yet with programming languages development, and increased fluency of the code, that order got reversed. Most fluent interfaces usually try to mimic natural language and unit testing frameworks are no different.

    In the assertion, we want to assure that some object matches some conditions. This is the natural language form, as if you were to explain your test code you’d probably say

    “In this test, I make sure that computed value is equal to 5”

    instead of

    “In this test, I make sure that 5 is equal to computed value”.

    Difference may not be huge, but let’s push it further. Consider this:

    Assert.That(Roses, Are(Red));
    

    Sounds about right. Now:

    Assert.That(Red, Are(Roses));
    

    Hm..? You probably wouldn’t be too surprised if somebody told you that roses are red. Other way around, red are roses, raises suspicious questions. Yoda, anybody?

    That doesn't sound natural at all

    Yoda’s making an important point – reversed order forces you to think.

    It gets even more unnatural when your assertions are more complex:

    Assert.That(Forest, Has.MoreThan(15, Trees));
    

    How would you reverse that one? More than 15 trees are being had by forest?

    This claim (fluency as a driving factor for modification) is somehow reflected in the change that NUnit has gone through – originally (Assert.AreEqual) it used expected before actual (old style). Fluent extensions (or to use NUnit’s terminology, constraint based – Assert.That) reversed that order.

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

Sidebar

Related Questions

When I try using unit tests (Microsoft vs2010-embedded testing framework) with MVC3, all unit
When unit testing, it is always hard to know how low down to the
I use the Silverlight Unit Testing Framework and it works pretty well. However every
What are some key UI design tips that every developer should know? While there
Is there a set of things that every JavaScript programmer should know to be
For my project I am using the integrated Visual Studio unit-testing framework but I
I've been experimenting with Rhino Mocks for unit testing my .Net Compact Framework application,
I have been hearing that with unit testing we can catch most of the
I programmed a GUI application who use the Unit testing framework . The application
i'm unit testing in vs2008 and every time i run now it says Executing

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.