Assert.IsInstanceOf passes on value null
See original GitHub issueDescription
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:
- Created 6 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AbhitejJohn Pull Request is up.
Merged. Thanks.