15,971 questions
-1
votes
0
answers
27
views
Angular 20 w Story 10 mocking a navigation click
I have an Angular 20 app, running Storybook 10. My component works perfectly, however, I'm trying to set up Storybook to mock a navigation link. I just can't seem to get it to work.
This is my ...
0
votes
1
answer
84
views
Mockito ArgumentMatchers.any(Class) for varargs parameter does not match
I have test method using mockito 5
@Test
public void test_increaseUserScore_Successful() throws CannotCreateCachedUserException {
when(cachedUserRepository
.existsById(...
2
votes
1
answer
69
views
Angular Karma getting Module not found: Error: Can't resolve
I have a large Angular App that works fine. (v20 if it matters)
I recently added a new service to my App.Component, and now I'm getting the following error. ONLY in Karma, the service works as ...
Best practices
1
vote
2
replies
168
views
Python - Should VTK be mocked in unit tests?
I am part of a team that is developing a general-purpose, Python-based 3D mesh viewer using the VTK (Python) library.
Read about VTK here: https://docs.vtk.org/en/latest/getting_started
Our Python ...
-1
votes
0
answers
59
views
Mocking native node: libraries in CJS and TypeScript
I am trying to mock some native node: libraries with Node's native node:test mocking on a CJS TypeScript project. Sometimes I have success when mocking without the node: prefix, other times not.
...
0
votes
0
answers
59
views
How to mock multipart/form-data with pytest?
I have a POST endpoint with fastapi that goes a little like this. This takes in an excel file and turns it into a pandas dataframe.
@router.post(
"/endpoint/upload_excel",
status_code=status....
0
votes
1
answer
52
views
I can only run my backend tests locally because all the instances of the mocked environment are created and into the actual db because of celery
I want to create tests but every time I run a test it triggers celery and celery creates instances into my local db. that means that if I run those tests in the prod or dev servers, then it will ...
0
votes
0
answers
72
views
Junit test case failing
I have a springboot maven project in which I have a very simple class which has a static method which takes in a http client, some configs and an object mapper
This class is under package com.cs....
0
votes
1
answer
98
views
Mocking nested functions in a Hardware Abstraction Layer
I am using ceedling to unit test a file called adc.c that depends on functions defined in HAL file stm32h7xx_hal_adc_ex.c. The documentation says that I should only include the top level header file ...
-1
votes
1
answer
39
views
Python unittest.mock fails when using pydantic.BaseModel
I have come across this problem when making my unit tests.
from unittest.mock import AsyncMock, patch
import pydantic
# class Parent(): # Using non-pydantic class works
class Parent(pydantic....
1
vote
1
answer
551
views
How to correctly configure the MapperConfiguration?
private readonly IMapper _mapper;
public CreateDepartmentRequestHandlerTests()
{
var config = new MapperConfiguration(cfg => cfg.AddProfile(new CreateDepartmentProfile()));
_mapper = ...
1
vote
1
answer
61
views
Mock patch sys.stdout to StringIO as a decorator
I am trying to mock.patch sys.stdout to StringIO as a decorator to record the output for testing.
As a 'with' statement it works this way:
with mock.patch('sys.stdout', new_callable = StringIO) as ...
1
vote
1
answer
126
views
How to mock SQL DB in Go unit tests?
I have a unit test testing service layer of my REST APIs. What I want to test is RegisterAccount in the service layer, which has dependencies on Repository (Database access layer). How do I mock in ...
2
votes
1
answer
69
views
Stub a method on a Thor CLI
I have a Thor class that has a getter method defined like this:
# Playgrounds CLI skeleton class.
# Commands are added from commands folder
class CLI < Thor
def self.exit_on_failure?
true
...
0
votes
0
answers
27
views
How can I Mock QueryMultipleAsync
How to Unit Test a Method Using QueryMultipleAsync?
I have a method that uses Dapper’s QueryMultipleAsync to retrieve multiple result sets from a database. What is the recommended way to unit test ...
0
votes
0
answers
37
views
Fake TableClient.QueryAsync<TableEntity>()
I'm trying to mock the return set in tableClient.QueryAsycn<TableEntity>(), but it continues to return empty lists. Is there anything glaringly obvious that I'm missing in my unit test.
The ...
0
votes
1
answer
86
views
Test case throwing NPE when calling mocked method
I am trying to write a Mockito test class to cover some db interaction. The test case I am writing is supposed to return a stub response when the database call is invoked, but it's throwing an NPE ...
1
vote
2
answers
68
views
Does GLib's "GTest" testing framework have any filesystem mocking functionality?
I'm writing tests for some code that interacts with the filesystem, and I want to assert that it writes the expected data to disk. My problem is that some of the code I want to test includes hardcoded ...
0
votes
0
answers
33
views
How to mock NgxSummernoteDirective
I am testing an angular component, which uses a summernote-editor from NgxSummernoteModule. The editor form ist set up by NgxSummernoteDirective using the methode createEditor():
createEditor() {
...
0
votes
0
answers
165
views
How to set up client (browser) msw worker in NextJS 15
I've been trying to setup Mock Service Worker in my NextJS 15 app (App Router) and faced problems with my client workers.
Here are my files with setupWorker/setupServer:
@src/shared/api/mocks/server....
1
vote
1
answer
148
views
How to handle return of unique_ptr in trompeloeil RETURN expectations
Hope this message finds you well.
I'm a little bit lost while using trompeloeil expectations syntax.
Let's say I have this:
#include <memory>
class IA {
public:
virtual ~IA() = default;
...
1
vote
0
answers
24
views
Pytest can't simulate stale API chunk in deduplication logic — fetch_recent_klines() never returns [] as expected
I'm testing a function `fetch_recent_klines()` that fetches 1m kline data from the Bybit V5 API.
It's designed to **halt and return `[]`** if it receives the same chunk of data twice — to detect stale ...
4
votes
1
answer
75
views
Why did the mocking API failed?
My project is huge, I tried to write unitest for one API session
import unittest
from unittest.mock import patch, MagicMock
from alm_commons_utils.mylau.lau_client import lauApiSession
class ...
0
votes
1
answer
112
views
Test with mocked service and another test with real implementation
TL;DR: I want to test the controller method that uses a service and the service itself that is being called, both in their respective unit test classes but can't do it since mocked bean replaces ...
0
votes
1
answer
98
views
Laravel - create facade partial mock
I created an helper class that wraps http calls to an external service using the Http facade: all the methods basically wraps the same http call structure: Http::withHeaders()->post() or get() ...
0
votes
1
answer
62
views
graphql-tools mock does not produce randomized response on repeated GQL requests
I followed the GraphQL Tools Mocking guide page to define a mock GQL server like below.
import express from 'express';
import { createHandler } from 'graphql-http/lib/use/express';
import { ...
3
votes
2
answers
121
views
Using $args in Add-Member inside a function
I'm trying to test a PowerShell function that sets the bindings for an IIS website. For the tests I want to create a Site object, that represents an existing website, with a Bindings property.
I'm ...
4
votes
1
answer
118
views
Create an instance in PowerShell of a .NET type without a constructor
I have a PowerShell script for setting up a website in IIS. It includes the following function:
function Set-IisWebsiteBinding (
[Parameter(Mandatory = $true)]
[string]$SiteName,
[...
0
votes
1
answer
86
views
How to "Don't Mock Things You Dont Own" with JDBC
This is a question about "testing patterns". How to "Don't Mock Things You Dont Own" with JDBC?
I tried to Proof Of Concept a JDBC Adapter in the below link, and after trying a ...
1
vote
1
answer
40
views
Flutter Mocktail : <type 'Future<PermissionStatus>' is not a subtype of type 'Permissions'>
I'm trying to mock the background_downloader package , specifically this line in my class I'm trying to mock:
var status = await fileDownloader.permissions.status(permissionType);
I keep getting error ...
0
votes
0
answers
64
views
Error Value of type Boolean incompatible with return type int
I am using:
junit 4.12
jmockit 1.54
Adopt JDK 21
Test case:
@Test(expected = Exception.class)
public void testCreateWareshousesNonSupplierDebugModeFalseException(@Mocked Iterator itr,
...
1
vote
1
answer
108
views
Mocking an embedded Jetty server request with test body content
I'm using the delightful Jetty org.eclipse.jetty:jetty-server:12.0.18 for an embedded HTTP server (not using Java EE servlets). Jetty passes an org.eclipse.jetty.server.Request to a custom handler, ...
1
vote
1
answer
130
views
Is it possible to mock out a character device file in userspace?
I have a user space application that opens a Linux device file handle (e.g., /dev/foobar) and then sends ioctls to it.
I need to replicate a specific series of answers from the device delivered back ...
0
votes
1
answer
73
views
mockk/spyk on WebView in instrumented tests
My app uses Jetpack Compose and includes a WebView.
I want to use Mockk (or something like that) in instrumented tests,
for example, I want my tests to check that
WHEN webView.canGoBack() THEN the ...
0
votes
1
answer
247
views
How to mock functions in streamlit unit tests?
I have a streamlit app, for which I'd like to create unit tests. I am unable to mock objects though.
I have a foo.py with the following content:
import streamlit as st
def dialog_func():
result = ...
0
votes
0
answers
67
views
ZKTeco MA300 Connection Issues: ECONNRESET on Node.js TCP Server
I'm developing a Node.js application to communicate with a ZKTeco MA300 biometric device over TCP. I'm running a mock server to test the connection, but I'm facing an issue where the connection gets ...
0
votes
0
answers
75
views
RSpec -- re-evaluate allow .and_yield when mocked method is called
In this code, sync_external accepts an array of posts and modifies it by calling a sync method from an external module ExternalService, which is mocked in the test.
Assume there's some reason to pass ...
2
votes
2
answers
180
views
Create std::filesystem::directory_entry without backing files for testing
I have some code iterating over files using std::filesystem. I am using dependency injection to mock out the directory_iterator logic, but I have trouble constructing a mocked directory_entry, which ...
0
votes
0
answers
75
views
Using explicit mocks for Typer CLI tests
I want to write unit-tests for a Typer based CLI, that will run the CLI with different inputs and validate correct argument parsing and input validation.
The point isn't to test Typer itself, but ...
0
votes
0
answers
140
views
ViTest Mock is not replacing function
For some reason in ViTest mocks are not replacing my real function. I have a main function here
const { handler1 } = require(./path/handler1)
exports.mainFunction = async (event) => {
try {
...
0
votes
0
answers
63
views
Looking for examples of how to unit test GraphQL resolvers?
I have a graphQL resolver that looks like this:
import { GraphQLSchema } from 'graphql';
import { buildSubgraphSchema } from '@apollo/subgraph';
...
const schema: GraphQLSchema = buildSubgraphSchema(...
1
vote
2
answers
56
views
Test Mock error - argument 1 expected [uint8 - 99] does not match actual [string - c9d778419a8ce7]
I am new to Go language , can you please let me know why I am getting this error in my code
argument 1 expected [uint8 - 99] does not match actual [string - c9d778419a8ce7]
Actual code
var ...
-1
votes
2
answers
36
views
Mocking external package struct that depends on HTTP request
I'm working on a terminal game based on this card game that gets its cards from deckofcardsapi.com. Cards are stored in a struct named Card in a package called card and each Card is stored in a struct ...
0
votes
2
answers
41
views
How to test that exception been thrown in Mockk
I need to verify that exception been thrown or that some logging method been called.
Here is my code
fun stop() {
println("----")
CoroutineScope(Dispatchers.IO).launch {
try {...
0
votes
1
answer
47
views
How can i mock user input in csv python
I want to mock add_new _costumer() in class NewCoustumer.
The
filename is**: main.py**
import csv
import os
class NewCoustumer():
def __init__(self,balance_checking = 0.0 , balance_saving = 0.0):
...
0
votes
1
answer
40
views
How to mock sftp list in munit with payload and attributes accessible inside foreach after list operation
Mock the sftp-list operation especially the attributes with file name and its path. These attributes are used in a for each loop are not available.
2
votes
1
answer
81
views
How to use `@pytest.mark.parametrize` and include an item for the default mock behavior?
I am creating a parameterized Mock PyTest to test API behaviors. I am trying to simplify the test code by testing the instance modified behavior, e.g. throw and exception, and the default behavior, i....
0
votes
0
answers
54
views
GPS Mock in Android checks
I have a program that derives last known location from each Location Provider on Android. After using a GPS mock app, some of the providers last known location was marked as mocked - even though the ...
0
votes
0
answers
57
views
AsyncMock not working when mocked using SQLAlchemy in FastAPI
I'm testing a FastAPI service that queries a database using SQLAlchemy's async execution. However, when I mock the database query, execute().scalars().all() returns an empty list instead of the ...
0
votes
1
answer
42
views
AsyncMock Returns Empty List When Mocking SQLAlchemy Async Execution in FastAPI
I have an app that basically ingests documents, stores their embeddings in vector form, then responds to queries that relate to the ingested docs.
I have this retrieval.py function which searches ...