85,790 questions
Best practices
0
votes
2
replies
23
views
Using pydantic_settings with Pytest
Goal
How can I use pydantic_settings in pytest? I want to have a .env.test environment file that has dummy values for all the environment variables. Some code has logic that depends on those variables ...
-2
votes
1
answer
42
views
Flutter Golden Screenshot Widget Integration Testing Shadow Mode [closed]
Why is it that my text fails to load in Flutter Widget Integration Testing in Shadow Mode.
I use Golden package to take screenshots, and no matter how long I pump and wait for environment to load, I ...
0
votes
0
answers
26
views
Missing methods in Laravel Livewire TestCase causing test failures [closed]
namespace Tests\\Feature;
use Tests\\TestCase; // Correct Laravel TestCase
use Livewire\\Livewire;
use Illuminate\\Foundation\\Testing\\RefreshDatabase;
class MyComponentTest extends TestCase
{
...
1
vote
0
answers
46
views
I start integration tests with `dotnet test`. They spawn IIS Express which fails ONLY on CI pipeline if I require code coverage
The test with coverage runs perfectly well locally:
C:\xyz\DevOps\xyz.DependencyInjection [master ≡]> dotnet test -c:Release --no-build -f net9.0 --filter "FullyQualifiedName~Tests....
0
votes
2
answers
51
views
Why is my continuous flow test code flaky?
I am trying to test the number of times a Flow is collected -
runTest {
var count = 0
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) {
dao.getEntities().collect {
...
0
votes
0
answers
53
views
DBT unit tests fail when a struct has too many fields
I am running DBT models on Databricks and I am starting to implement unit tests for them.
I have the following DBT unit test :
unit_tests:
- name: test_my_model
model: my_model
given:
...
-1
votes
0
answers
37
views
Unit test for React/Chakra
This is my parent component.
import { useState } from 'react';
import VButton from 'ui-components/src/v2/VButton.jsx';
import { Provider } from 'ui-components/src/v2/providers/chakra.jsx';
import { ...
1
vote
0
answers
18
views
Ginkgo Receive(BeEquivalentTo()) fails when comparing struct with interface payload
When writing Ginkgo unit tests, I ran into an issue asserting data received from a channel that contains a struct with an interface{} field.
Here's my models.go
type WsBaseMsg struct {
Type ...
1
vote
1
answer
52
views
Angular unit testing - using debugElement.queryAll to get instances of a button
Running this unit test in Angular 21 always fails with the following error:
× should toggle showSettings when settings button is clicked (440231 ms)
● DrawerComponent › should launch settings ...
2
votes
3
answers
103
views
How to Unit Test Multi-Stage Member Functions in Polymorphic Classes Used with std::variant?
I have three processor classes that share a common interface for polymorphic behavior using std::variant and std::visit. Each processor has a processData() member function that internally consists of ...
0
votes
1
answer
45
views
Check return value / thrown error or exception and calls to print during unit tests in Dart
The following code is a simplification of the code that I have and may not disclose:
class Logger {
var _loggingStarted = false;
void startLogging() {
if (!_loggingStarted) {
...
Best practices
1
vote
2
replies
163
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 ...
0
votes
1
answer
49
views
Custom error objects for Mongoose schema paths
Take the following Mongoose schema.
const userSchema = mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
minLength: 3
},
name: ...
2
votes
3
answers
149
views
How to create test executables in Makefile in C?
I want to build make test with Makefile, and the test target should generate <file_name>_test executable based on the folder tests/<file_name>.c. All tests/*.c files have a main() function....
1
vote
2
answers
142
views
PHPUnit tests get awfully slow when all tests are run at once [closed]
I have a problem which I find awfully hard to debug:
In my application, I currently have about 1000 tests, so not much. They are split across several directories (tests/someDir, tests/someOtherDir, ...
1
vote
1
answer
82
views
Mockito spying on a class which contains a static method which calls another static method
I am trying to get a unit test to work using Mockito 5.14.2. The method I am trying to unit test is a static method (m1). Within the same class Myclass1 there is another static method (m2) which ...
0
votes
1
answer
76
views
Issue with Pycharm pathing for the use of a unit test
I'm taking a course using the pycharm learn feature and can't get past a unit test, I think it's saying that it can't find it in the correct spot. How do I fix this?
Error:
Traceback (most recent call ...
4
votes
0
answers
211
views
`dotnet test` is inconsistent when it comes to showing the total number of unit tests at the end
I have a solution with many projects. When I run dotnet test, it selects all my xUnit projects and seems to correctly execute all of them. But at the last line of what dotnet test prints, the number ...
1
vote
1
answer
99
views
Unit testing with TestFX (and Mockito)
It is my understanding that you have to @ExtendWith(MockitoExtension.class) to run a test class with Mockito runner. And to use TestFX to test a JavaFX application you would need to @ExtendWith(...
1
vote
1
answer
101
views
How to control test class execution order in JUnit 5 suites?
I'm organizing my tests using JUnit 5's @Suite and @SelectClasses, but need to control the execution sequence of the test classes. According to the documentation, @SelectClasses doesn't guarantee ...
-1
votes
0
answers
67
views
CS0122 when writing basic unit tests the 'default way' for VS2022 and VS2025
The information in the first relevant Q&A I found InternalsVisibleTo does not work has gotten rather out of date. I usually test code just with print statements and #debug preprocessor guards, but ...
1
vote
1
answer
102
views
Does adding opens configuration in maven surefire plugin effect anything outside the test scope?
I'm working on a user-related service that handles personal information. While writing unit tests with Mockito, I ran into dependency issues with Byte Buddy, which prevented me from using the latest ...
-3
votes
0
answers
53
views
How to avoid breaking all tests whenever I add new dependencies?
I keep running into an annoying issue where my integration tests break every time I add a new dependency to one of my services.
For example, let’s say I have three services: A, B, and C.
class ...
0
votes
2
answers
88
views
How to remove setTimeout in Vitest?
I have a function that allows users to register. After successful registration, the user is redirected to the home page (after 5 seconds). Before being redirected, the user receives a toast ...
3
votes
2
answers
151
views
Verify object value returns false when the value is changed in code using MOQ
I am creating a test to verify an object is passed to a method then verifying that the params match to the method in the call I am testing. The problem I am having that the object I am verifying ...
0
votes
1
answer
43
views
Mocking Vitest functions for testing Pinia storage
I am struggling adding mocked methods when testing a Pinia store's functionality. There is very little documentation relating to actually testing the stores themselves, as most Pinia's official ...
2
votes
2
answers
103
views
Are these unit tests using Moq testing anything?
I am attempting to test a repository method using a moq with a setup in the test. As far as I can tell, this is not testing the method but only testing the test.
Here is an abbreviated version of the ...
0
votes
0
answers
55
views
How to mock usager of Laravel scopes for unit testing?
I'm using Laravel 12 along with Pest (using Mockery), and I have this method :
public function destroy(array $ids): array
{
$data= Item::findAllByFieldIn('id', $ids)->get();
// ...
1
vote
1
answer
54
views
Poxing a mocked generic method with Moq
I provide a generic provider for Json serialization:
public interface IJsonSerializerProvider
{
T? Deserialize<T>(string value);
string Serialize(object? obj);
object? ...
1
vote
2
answers
129
views
Why are ggplot2 font family changes not reflected in vdiffr::expect_doppelganger()?
In creating unit tests for an r package that provides a custom ggplot2 theme, I've noticed that the snapshots created by vdiffr::expect_doppelganger() aren't reflecting font family changes that work ...
1
vote
1
answer
67
views
How to directly test ActionController::RoutingError for an invalid path in Ruby-on-Rails-7.1?
In Rails Controller tests of an invalid route, this used to work before Rails-7.1 (in Minitest):
assert_raises(ActionController::RoutingError){ get "/non_existent" }
In Rails-7.1 (or later),...
0
votes
1
answer
31
views
How to expose kotlin package `import kotlin.test.Test` for a bazel `kt_jvm_test`
I'm trying to compile a very simple kotlin test file based off of the example at https://kotlinlang.org/docs/jvm-test-using-junit.html#create-a-test in order to prove that my setup in bazel is ...
-1
votes
1
answer
53
views
Accessing calls/args in a global mock with spied functions
In a large Vue 3 app, we have some helper modules that are imported into various components. One of these helpers returns the root node, which itself contains many other methods.
In the app calls to ...
1
vote
0
answers
55
views
System.AccessViolationException occurs when running a C# Godot unit test for Node2D object
I am building a card game using Godot 4.5, with C#. I am trying to unit test a Card object that inherits from Node2D, but when I attempt to run the test, I get the following exception:
Exception has ...
0
votes
2
answers
104
views
How to create test cases in Polygon for Python program with random values?
I have a beginner Python program that generates random output and does not take any input. For example, it simulates rolling a dice 5 times and prints the results, their sum, and average:
import ...
0
votes
0
answers
58
views
Django Testing in microservices with more than 1 db running
I would like to ask about a certain topic that is tough one. Im working in a project that has microservices architecture with more than 1 databases running every time. in django, how can I perform ...
1
vote
2
answers
116
views
How to fake a second function call using FakeItEasy?
I have a class that looks like this:
public int DoWork(int value)
{
return value + GetDataFromDB();
}
public int GetDataFromDB()
{
return 10;
}
In the real world the second function goes ...
0
votes
0
answers
32
views
Gradle tasks for multiple test types
Our project currently has two types of tests: Tests that communicate with the MySQL test database and tests that don't.
The database tests should be run in sequence as they mutate the same database, ...
0
votes
0
answers
52
views
Moq.Of<T> setup for Action<T> with a callback and capturing method parameter
Lets say we have the following interface:
public interface IGetRandomString
{
void Init();
bool IsInited { get; }
//returns random string of length chars
string GetRandomString(int ...
0
votes
0
answers
67
views
Swift snapshot testing produces a different image on CI
I'm using point free's swift snapshot testing for capturing images of SwiftUI views.
It works well so far, but when I use SwiftUI's FocusState I get a different output on CI compared to my local ...
1
vote
1
answer
88
views
BOOST_DATA_TEST_CASE with dataset = list of tuples
My data-driven Boost test-case takes several parameters. I chose to group them in a std::tuple. So the resulting dataset consists in a list of tuples.
Beyond a 1-element tuple (test1 below), the ...
1
vote
1
answer
95
views
Moq: how to create a HttpRequest object containing a HttpPostedFile?
I am working with ASP.NET/.NET 4.8 application.
My action method is as follows:
public class TestController: System.Web.Http.ApiController
{
// pseudo code
public async Task<...
0
votes
0
answers
32
views
Setup NSubstitute return value complaints that I do not dispose the result of the mocked method
I'm using NSubstitute to mock the creation of a HttpClient when calling IHttpClientFactory.CreateClient() in an ASP.NET Core 8 Web API.
The code is as follows:
httpClientFactory = Substitute.For<...
1
vote
1
answer
429
views
How to correctly configure the MapperConfiguration?
private readonly IMapper _mapper;
public CreateDepartmentRequestHandlerTests()
{
var config = new MapperConfiguration(cfg => cfg.AddProfile(new CreateDepartmentProfile()));
_mapper = ...
0
votes
2
answers
84
views
How do I set the spdlog log level in a Catch2 unit test?
I have a C++ file which defines multiple Catch2 unit tests.
Some of these unit tests call code which uses SPDLOG_TRACE. By default trace level logs are not shown.
What options are available to enable ...
0
votes
1
answer
124
views
A C++ unit test which tests a function which takes a lambda as an argument
I have written a C++ Unit Test which has a design problem.
The test is relatively straightforward. I am testing some kind of "iobuffer" object. There is a function recv which is used to copy ...
1
vote
1
answer
55
views
How to mock an imported hashPassword function in Jest when testing a registerUser method?
Question
I have a registerUser method that imports a hashPassword function from a local utility module.
// registerUser.ts
import { User } from "../models/user.model";
import { hashPassword }...
1
vote
1
answer
36
views
Unable to complete setting up the CounterFeatureTests class
I am following the guide here in the Getting started document to complete the Testing for your feature module, but I keep getting the following exceptions even if my feature struct conforms to the ...
0
votes
0
answers
48
views
Forge test fails with --match-test(Fork mainnet) but passes with forge test(anvil)
I’m running into an issue with my Foundry tests and can’t figure out what’s going wrong.
When I run on a local Anvil fork, everything passes just fine. But when I switch to a mainnet fork, I keep ...
4
votes
0
answers
65
views
Unable to pass macro from .yml to header file in ceedling
I am working on a project for which I need to run unit test using ceedling framework.
I have done the necessary config in the .yml file.
During the build stage, one of the macros ...