Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [unit-testing]

Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

unit-testing
0 votes
0 answers
6 views

How to test a service layer in spring with mockito?

I mocked repository and service. I used when().thenReturn() method with verify but it seems that repository and service are null. For both mocked service and repository the value returned by calling ...
Hekima's user avatar
  • 1
0 votes
1 answer
10 views

What are the possible ways we can handle the case when the setup code of a test fixture requires to be tested itself without violating best practices?

What are the possible ways we can handle the case when the setup code of a test fixture requires to be tested itself without violating best practices? Consider the following code in C# 12.0/.NET 8.0 ...
Hashkoon's user avatar
-1 votes
0 answers
6 views

WebClient static mock is not working the second time is called in a test

I have the next static mock: try (MockedStatic<WebClient> webClientStatic = Mockito.mockStatic(WebClient.class)) { webClientStatic.when(WebClient::builder).thenReturn(...
rasilvap's user avatar
  • 1,979
0 votes
0 answers
15 views

How to write a test against randomly selected values from a collection?

I have a function which selects a random value from an array to be returned: export function selectMovieUnderDuration(options: IStreamRequest, movies: Movie[], prevMovies: Movie[], duration: number): ...
JSArrakis's user avatar
  • 789
0 votes
0 answers
7 views

Is there a way to make a variable available globally from the `beforeAll` function in Vitest?

For example, I want to make this something variable from inside the beforeAll block grabbable from my unit test suites. import { beforeAll } from 'vitest' beforeAll(async () => { let something = ...
jiamijiang's user avatar
0 votes
2 answers
31 views

Is there a generic way to use SetReturnsDefault in Moq

I have a data access interface looking roughly like this: public interface IDataRepository { DatabaseResult<Customer> GetAllCustomers(); DatabaseResult<Report> GetAllReports(); ...
user1151923's user avatar
  • 1,862
2 votes
1 answer
14 views

Angular: how to fix Error: NG03600: Angular detected that the `AnimationBuilder` was injected, but animation support was not enabled

When I ran Angular unit test I got the following error many times: Error: NG03600: Angular detected that the AnimationBuilder was injected, but animation support was not enabled. Please make sure that ...
L. Kvri's user avatar
  • 1,612
0 votes
0 answers
36 views

Is MockObject necessary - GTest segmentation fault

Google test with fixture's got segmentation fault Inextricably I find segmentation fault every time compiling Google unit test. In explanation I compile Google test without problem for test without ...
gzifl-67's user avatar
0 votes
0 answers
17 views

how to mock a third party library and assert its functions were called (or spyon) with jest?

I am working with ngrx and signalr, and writing a unit test for my ngrx effect responsible for building, starting and stopping the signalR hub. this is my effect: import {HubConnection, ...
Natalia Cáceres's user avatar
1 vote
1 answer
16 views

Picocli unit test failed for registering subcommands programmatically

In picocli we can register subcommands declaratively and programmatically. It works both way, but the unit test according the docs failed for the programmatically version. This is the unit test: @Test ...
Dominik's user avatar
  • 1,412
0 votes
0 answers
24 views

create migrations in an unit test project

I have an ASP.NET Core Web API project with EF Core and a SQL Server database using the repository pattern. All works fine. I added to the solution an xUnit test project and referenced the Web API ...
derstauner's user avatar
  • 1,716
0 votes
0 answers
11 views

TypeScript JSX Syntax Error in Jest Mock for react-native-modal: Operator ‘>’ cannot be applied to types ‘View’ and ‘{ children: React.ReactNode; }’

I’m trying to create a Jest mock for react-native-modal in a React Native project using TypeScript. However, TypeScript doesn’t recognize the return statement as valid JSX. It throws the following ...
Mike S.'s user avatar
  • 2,706
1 vote
1 answer
29 views

Mock Google's StorageClient ListObjects method using Moq

I'm trying to unit test the following method public List<string> GetFilesInGCS(string bucket, string node) { List<string> fileNames = new List<string>(); try { ...
Jason Everett's user avatar
0 votes
1 answer
29 views

Why is my NestJS unit test not getting full coverage?

I have a pretty simple NestJS guard for SAML auth which works just fine export class SamlAccessGuard extends AuthGuard('saml') implements CanActivate { private readonly isDevelopment = process.env....
Chris Barr's user avatar
0 votes
1 answer
15 views

How to test the return type line of a NestJS resolver with jest

I am new to NestJS and trying to unit test my files to have a good code coverage starter point. I managed to test everything in my app, except an auth.resolver.ts Here it is : import { Resolver, ...
Enzo's user avatar
  • 183

15 30 50 per page
1
2 3 4 5
5713