question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assert.IsInstanceOf passes on value null

See original GitHub issue

Description

Assert.IsInstanceOfType succeeds when value is null, while the MSDN specifies it should throw an error. AssertFailedException : ‘value is null or expectedType is not found in the inheritance hierarchy of value.’ https://msdn.microsoft.com/en-us/library/ms243733.aspx

Steps to reproduce

Create a standard .net core test project from visual studio 2017, and create a dummy class. then use the following method: public void TestMethod1() { Assert.IsInstanceOfType(null, typeof(Dummy)); }

Expected behavior

The test should throw AssertFailedException and fail

Actual behavior

The test passes

Environment

Windows Server 2016, MSTest.Framework version 1.1.11 and 1.1.17 MSTest.TestAdapter version 1.1.11 and 1.1.17

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
LarsCeliecommented, May 10, 2017

@AbhitejJohn Pull Request is up.

0reactions
AbhitejJohncommented, May 10, 2017

Merged. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is null check needed before calling instanceof?
No, a null check is not needed before calling instanceof . It always returns false if its value is null . As per...
Read more >
Assert.IsInstanceOf
IsInstanceOf succeeds if the object provided as an actual value is an instance of the expected type. Assert.IsInstanceOf(Type expected, object actual); Assert.
Read more >
unit test - Check with instanceof always returning true!
As far as I know, instanceof in Apex has always returned true when the operand is null, which is not consistent with Java...
Read more >
Assert (AssertJ fluent assertions 2.9.1 API)
Verifies that the actual value is not null . Example: // assertion will pass assertThat("abc").isNotNull(); assertThat(new HashMap<String, Integer>()) ...
Read more >
Spring Assert Statements
On the other hand, we can check if an object is null using the isNull() method: public void replaceBattery(CarBattery carBattery) { Assert.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found