<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3" -->

---
title: MSTest Assert class - an overview | daily.dev
description: An introduction to the MSTest Assert class beyond the basic IsTrue method, covering AreEqual overloads for ints, doubles/singles with delta tolerance, strings...
canonical: https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: MSTest Assert class - an overview | daily.dev
og:description: An introduction to the MSTest Assert class beyond the basic IsTrue method, covering AreEqual overloads for ints, doubles/singles with delta tolerance, strings...
og:url: https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3
og:image: https://api.daily.dev/og/posts/wNCtQPdf3.png
og:image:alt: MSTest Assert class - an overview
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# MSTest Assert class - an overview

**[Code4IT](https://daily.dev/sources/code4it)** · 10 min read · 0 upvotes · 0 comments

## Summary

An introduction to the MSTest Assert class beyond the basic IsTrue method, covering AreEqual overloads for ints, doubles/singles with delta tolerance, strings (including case sensitivity, CultureInfo, and the Turkish I problem), objects and structs (including overriding Equals), AreSame for reference comparison, IsInstanceOfType/IsNotInstanceOfType, IsNull, and ThrowsException with its generic type-matching behavior. Each example includes working C# test code. Part one of a planned series that will later cover StringAssert and CollectionAssert.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/mstests-assert-overview>

## Questions this post answers

### How do I compare two objects with Assert.AreEqual in MSTest when they have the same property values?

Assert.AreEqual fails on two distinct object instances with identical property values because default equality compares object references, not field values. To make the comparison pass, override the Equals method on the class to define custom value-based equality, then Assert.AreEqual will use that override when comparing instances.

_daily.dev surfaces practical testing fixes like this for developers writing C# unit tests._

### Why does Assert.AreEqual fail when comparing float or double values in MSTest even though they look equal?

Floating-point values are rounded based on their internal representation, so direct equality checks often fail even when numbers look the same. MSTest's Assert.AreEqual overload for Single and Double types requires a third delta parameter specifying the acceptable margin of difference; the test passes only if the actual value is within that delta of the expected value.

_developers tuning floating-point test assertions can find more MSTest patterns on daily.dev._

### What happens if Assert.ThrowsException expects one exception type but the code throws a different exception type in MSTest?

The test fails, because ThrowsException checks the exact runtime type of the caught exception against the generic type parameter supplied, not just whether any exception was thrown. If a method throws ArgumentNullException but the test calls Assert.ThrowsException<Exception>, the type comparison fails and MSTest reports a 'wrong exception thrown' message rather than passing.

_daily.dev helps C# developers track exception-handling test gotchas like this one._

## Similar posts on daily.dev

- [Enhancing MSTest CollectionAssert.IsSubsetOf Error Messages](https://daily.dev/posts/enhancing-mstest-collectionassert-issubsetof-error-messages-yniiniqoi) · C\# Corner · 0 upvotes · 0 comments
- [Thinking about tests: assertions and matchers](https://daily.dev/posts/thinking-about-tests-assertions-and-matchers-cbfp1ttlt) · RUBYLAND · 1 upvotes · 1 comments
- [assert\(\): A modern How To](https://daily.dev/posts/assert-a-modern-how-to-mky6fdnmw) · Hacker News · 0 upvotes · 0 comments
- [Fortran - Testing - More assertion functions](https://daily.dev/posts/fortran---testing---more-assertion-functions-cxmqx7aok) · Matthias Noback · 0 upvotes · 0 comments
- [C\# String Comparison: Equals, OrdinalIgnoreCase, StringComparer, and Culture Pitfalls](https://daily.dev/posts/c-string-comparison-equals-ordinalignorecase-stringcomparer-and-culture-pitfalls-na8wbs2pq) · We Are .NET · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"MSTest Assert class - an overview","url":"https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3"},"datePublished":"2026-10-04T13:07:39.975Z","dateModified":"2026-10-04T13:16:15.527Z","description":"An introduction to the MSTest Assert class beyond the basic IsTrue method, covering AreEqual overloads for ints, doubles/singles with delta tolerance, strings...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e17a8e1f19f2bb1f7f422a64f06ffa02?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e17a8e1f19f2bb1f7f422a64f06ffa02?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,.net,c#","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"MSTest Assert class - an overview"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/mstest-assert-class---an-overview-wnctqpdf3#faq","mainEntity":[{"@type":"Question","name":"How do I compare two objects with Assert.AreEqual in MSTest when they have the same property values?","acceptedAnswer":{"@type":"Answer","text":"Assert.AreEqual fails on two distinct object instances with identical property values because default equality compares object references, not field values. To make the comparison pass, override the Equals method on the class to define custom value-based equality, then Assert.AreEqual will use that override when comparing instances. daily.dev surfaces practical testing fixes like this for developers writing C# unit tests."}},{"@type":"Question","name":"Why does Assert.AreEqual fail when comparing float or double values in MSTest even though they look equal?","acceptedAnswer":{"@type":"Answer","text":"Floating-point values are rounded based on their internal representation, so direct equality checks often fail even when numbers look the same. MSTest's Assert.AreEqual overload for Single and Double types requires a third delta parameter specifying the acceptable margin of difference; the test passes only if the actual value is within that delta of the expected value. developers tuning floating-point test assertions can find more MSTest patterns on daily.dev."}},{"@type":"Question","name":"What happens if Assert.ThrowsException expects one exception type but the code throws a different exception type in MSTest?","acceptedAnswer":{"@type":"Answer","text":"The test fails, because ThrowsException checks the exact runtime type of the caught exception against the generic type parameter supplied, not just whether any exception was thrown. If a method throws ArgumentNullException but the test calls Assert.ThrowsException<Exception>, the type comparison fails and MSTest reports a 'wrong exception thrown' message rather than passing. daily.dev helps C# developers track exception-handling test gotchas like this one."}}]}
```

