Skip to content

Assert.IsInstanceOf passes on value null #178

Closed

Description

@LarsCelie

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

Activity

  1. LarsCelie commented on May 9, 2017

    @LarsCelie
    ContributorAuthor

    When i cloned testfx, i was able to reproduce this as well.
    [TestMethod] public void InstanceOfTypeShouldFailWhenValueIsNull() { // Assert.IsInstanceOfType(null, typeof(AssertTests)); FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsInstanceOfType(null, typeof(AssertTests)); }

    the commented out line would fail if ran, and the frameworkv2 version will succeed.

  2. AbhitejJohn commented on May 9, 2017

    @AbhitejJohn
    Contributor

    Thanks Lars Celie (@LarsCelie) for filing this. It looks like we are missing a check here. Marked this as an up-for-grabs issue - its a small change.

  3. LarsCelie commented on May 9, 2017

    @LarsCelie
    ContributorAuthor

    You can assign me as well, trying to fix it.

  4. added a commit that references this issue on May 9, 2017
    395f954
  5. AbhitejJohn commented on May 9, 2017

    @AbhitejJohn
    Contributor

    Great. Thanks Lars Celie (@LarsCelie) .

  6. LarsCelie commented on May 10, 2017

    @LarsCelie
    ContributorAuthor

    Abhitej John (@AbhitejJohn) Pull Request is up.

  7. AbhitejJohn commented on May 10, 2017

    @AbhitejJohn
    Contributor

    Thanks a bunch Lars Celie (@LarsCelie) . Had a few small comments. Will merge it soon after.

  8. AbhitejJohn commented on May 10, 2017

    @AbhitejJohn
    Contributor

    Merged. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

help wantedUp for grabs; can be claimed by commenting.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions