New answers tagged unit-testing
0 votes
Test method is inconclusive: Test wasn't run. Error?
The projects in my solution were all in .NET 6, but I didn't have the .NET 6-sdk installed, but only the .NET 8-sdk. Installing the .NET 6-sdk solved the issue. Looks I have some upgrading to do...
Advice
1 vote
0 replies
0 views
How can I tell Shouldly to ignore the concrete type of collections when comparing objects?
You’re not doing anything wrong — this is just a limitation of Shouldly. ShouldBeEquivalentTo compares concrete types, not just structure. So even though both List<T> and ReadOnlyCollection<T&...
0 votes
DataTestMethod and DataRow attributes in MSTEST
The accepted answer is now obsolete. As per the following MS Learn document, the [DataTestMethod] attribute is deprecated and will be removed in a future version of MSTest. Use the normal [...
Tooling
0 votes
0 replies
0 views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
You don't specify how you are creating DataTable s but assume it is using reflection e.g. FastMember library. Why not create a custom attribute to store column position (e.g. "Ordinal") and ...
0 votes
Swift XCTest unit tests in a MacOs Command Line Tool project
Preliminary remark: Having the same problem, I tried to solve it following a dozen of webinars and articles on XCTest without success. The comments of this question finally solved the problem. I ...
Advice
1 vote
0 replies
0 views
How to Test Builder Pattern that Returns an Object with No Accessors?
Don’t waste time writing unit tests for code that everybody can recognize within a few seconds as being correct (or too trivial to be incorrect). Focus on test cases for the actual execution of the ...
Tooling
1 vote
0 replies
0 views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
You can always connect with an account used for read-only access to the DB. It is a double-edged sword in my experience as I have been in environments where the SQL scripts created fall out-of-sync ...
Tooling
0 votes
0 replies
0 views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
Unit testing a database connection and general questions on database-dependent code and unit testing But then does it matter what you call it - if it mitigates a risk for you then job done?
Advice
0 votes
0 replies
0 views
How to Test Builder Pattern that Returns an Object with No Accessors?
Thanks for pointing out the signatures not being clear. I corrected the build() method on the AddCommandBuilder to return an AddCommand instead of a AddCommandBuilder.
Tooling
0 votes
0 replies
0 views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
Is using a database connection in a unit test bad practice? Or am I wrong? I say this out of ignorance.
Advice
0 votes
0 replies
0 views
How to Test Builder Pattern that Returns an Object with No Accessors?
Whoever wrote that class is really trying to make things hard for everyone. The right way to do this is to convert AddCommand into a record and simply assert the values. If you're on an old JDK that ...
Tooling
1 vote
0 replies
0 views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
I'm using EF Core for managing my database schema. Which doesn't have any support for UDTT. So I built my own. I define each UDTT based on an EF Core keyless entity type with an added [SqlType] ...
Advice
0 votes
0 replies
0 views
How to Test Builder Pattern that Returns an Object with No Accessors?
and verifying that execute() returns a valid Source object.
Tooling
0 votes
0 replies
0 views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
You're on the right track. Use SQL Server as the single source of truth and avoid exporting and parsing SQL files, i.e. read the column names and order, for example: public sealed record UdttColumn(...
Advice
0 votes
0 replies
0 views
How to Test Builder Pattern that Returns an Object with No Accessors?
By checking the return value of build? (The signatures don’t make sense though.)
Tooling
1 vote
0 replies
0 views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
Have you considered querying the database itself to compare the type definition against the C# type? e.g.: SELECT sc.* FROM sys.columns sc JOIN sys.table_types stt ON stt.[name] = N'DefinedType' AND ...
0 votes
How do I keep Visual Studio deleting the Deploy directory at the end of MSTest run
According to Microsoft documentation on the .runsettings file, this behavior can disabled via configuration. Add a file named .runsettings as a solution item or a project item with the following ...
Best practices
0 votes
0 replies
0 views
Testing with corroutines
The parameters First, as a code style requirement, such a class should take a CoroutineScope parameter, not a CoroutineContext. CoroutineContext is used in APIs when it will be appended to an existing ...
0 votes
How to mock ResizeObserver to work in unit tests using react testing library
We had similar issues in our environment. The cleanest solution in our vitest environment - add code to test-setup.ts as follows: const ResizeObserverMock = class { observe(): void { // void } ...
2 votes
Accepted
NSubstitute: ToDictionaryAsync: Only sources that implement IDbAsyncEnumerable can be used for Entity Framework asynchronous operations
The tested code was using the wrong extension: ToDictionaryAsync from System.Data.Entity instead of ToDictionaryAsync from Microsoft.EntityFrameworkCore
Best practices
0 votes
0 replies
0 views
Do anyone's know how to mock supabase in Flutter?
The core problem isn't Flutter-specific. Supabase's query builder is a fluent chain (.from().select().eq().single()), so your mock has to be chainable too. The fix is two things: dependency injection ...
Best practices
1 vote
0 replies
0 views
What are best practices for unit testing with Jest in JavaScript?
It's up to you how to structure it. Jest is configured by default to use __tests__ directory or spec/test file suffixes. For unit tests, it makes sense to use prefixed files for 1:1 match with tested ...
Best practices
0 votes
0 replies
0 views
What are best practices for unit testing with Jest in JavaScript?
When should I mock something vs just using the real implementation is general and not specific to JavaScript etc. Have you looked into that at all? Should you aim for 100% code coverage? It sounds ...
0 votes
Mocked service throws NG0201: No provider found for `_HttpClient` error
This usually happens when you transitively use a service, which isn't provided in the file under test. In the case of the missing HttpClient, the easiest way is typically to provide the service itself ...
0 votes
ExpectedExceptionAttribute is not working in MSTest
Try the new way Assert.Throws<ArgumentNullException>(() => throw new ArgumentNullException("test"); );
0 votes
Run Django tests in the VSCode Test explorer?
I tried to follow Benoit Blanchon’s answer, but the linked documentation has not helped me, because my project does not contain manage.py. I succeeded with the following steps: Install pytest-django ...
Top 50 recent answers are included
Related Tags
unit-testing × 85698c# × 13211
java × 11277
python × 8078
javascript × 7595
mocking × 7151
testing × 6643
junit × 5140
jestjs × 5038
mockito × 4512
angular × 4216
jasmine × 4151
android × 3488
moq × 3351
angularjs × 3306
reactjs × 2823
php × 2770
.net × 2756
node.js × 2594
karma-jasmine × 2554
c++ × 2349
nunit × 2333
tdd × 2238
phpunit × 2237
typescript × 2165