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.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
7 views

ERROR(CLI12): Missing parameter from command line option

I am creating unit tests, and I am able to fully compile and test them locally. However, the Jenkins build ends up failing. I am wondering if anyone knows what this error means. 1/32 Test #1: ...
Andrew's user avatar
  • 1
1 vote
1 answer
19 views

How to create a pytest fixture to clean a database

I'm working on a Python project with FastAPI and Pony ORM. We're creating unit tests for each module of the program, and we want to be able to run all the tests together (there's one test file for ...
Adolfo Banchio's user avatar
1 vote
1 answer
22 views

How to mock the elastic search SDK for go?

I'm developing an api in go, which communicates with elastic search using SDK v8. But I'm having difficulty simulating elastic methods for unit tests I have the following function: func DocumentExists(...
wiliamvj's user avatar
0 votes
1 answer
25 views

I am trying to test a command handler in .NET 6. I had to add DynamicProxyGenAssembly2 attribute. How to remove it?

I have use CQRS pattern in my .NET 6 project. I have a CreateQueryCommandHandler. Its access modifier is set to internal which I cannot change. I am trying to unit test my command handlers. I have ...
Hardik Dhuri's user avatar
1 vote
0 answers
13 views

How can you create a Mock of a method that extends a sealed class?

I have created a sealed class as follows and created extension methods. sealed class Result<S, E extends Exception> { const Result(); } final class Success<S, E extends Exception> ...
sub's user avatar
  • 137
0 votes
1 answer
26 views

getting error message for a return value from a mocked function

I have this Dart code which uses Equatable and Oxidized packages: import 'package:equatable/equatable.dart'; import 'package:oxidized/oxidized.dart'; abstract class Failure {} class ...
Ουιλιαμ Αρκευα's user avatar
0 votes
0 answers
11 views

Jest mock a class instance originally imported from a barrel file

I am trying to mock a Vuex store imported by an otherwise-vanilla TypeScript class. For the sake of this question, I think it's safe to ignore the Vuex internals and just try to provide an instance of ...
nshew13's user avatar
  • 3,050
0 votes
0 answers
4 views

SSH.Net.Sftp Cannot mock non-overridable property

Using a unit test I need to bypass this code and reach return IsFile; line. The variable client is my own wrapper around SSH.Net SftpClient which I can mock. The enum SftpCheckPathExistence is my own ...
Mihai Socaciu's user avatar
0 votes
1 answer
16 views

Writing unit tests for simple Angular functions which using inject() method in Angular 16

After Angular CanActivate interface became deprecated, I've changed my guards for simple const functions based on official documentation. For example here is my inverseAuthGuard method, which seems ...
faklyasgy's user avatar
  • 826
0 votes
1 answer
13 views

Test suspended function returning Flow in runTest Scope is not finishing. After time it giving timeout error

I am testing the suspend function that returns the flow. I am able to collect that flow in the runTest scope but this test never ends and gives a timeout error after sometime. suspend fun getData() : ...
Vinayak Khedkar's user avatar
0 votes
1 answer
44 views

Why got 320 code in http testing on validation error?

In laravel 10 app I have a test method : public function testAdded() { // Test Data Setup $tagModel = Tag::factory()->make([]); // model only in memory // Test Action // $tagModel-...
mstdmstd's user avatar
  • 2,267
0 votes
0 answers
18 views

i am getting error request failed 404 from a api when i do widget and unit testing in flutter

this is the test file import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_train/components/api_handling/...
Ashutosh Nayak's user avatar
0 votes
0 answers
17 views

Do Equatable need to be immutable

Is there real case scenarios of not following immutable leading to wrong hash outcome? I've made a test case to test the non-immutable class and was expecting it to have an error. In reality we do not ...
Nikita Shadkov's user avatar
0 votes
0 answers
3 views

XState mock createActorContext

I have a provider that looks like: import { ReactNode } from 'react' import { createActorContext } from '@xstate/react' import mainMachine from 'machines/transmitSdk' export const MainMachineService =...
Jamie's user avatar
  • 1,911
0 votes
2 answers
64 views

Problems testing values saved in android Intent (extras always null)

I have the following Android Intent extension: import android.content.Intent import android.os.Parcelable import java.io.Serializable fun Intent.addNewTaskFlags(): Intent = apply { addFlags(...
Pierre Vieira's user avatar
0 votes
0 answers
18 views

How to configure global pattern for Net Core Test Explorer in visual studio code?

I'm developing a Net Core App and I need to make some test for Repository. Nevertheless I had some problem for Net Core Test explorer configuration. When I settle down the test project path, it ...
Turing's user avatar
  • 23
-2 votes
0 answers
54 views

Unit testing issues of cmake and googletest [closed]

My root folder name is "Example" Here is the directory tree of my folders ├── .vscode ├── build ├── build-vscode ├── CMakeLists.txt ├── fixedpoint.cpp ├── fixedpoint.h ├── googletes └── test ...
Azraf Sami's user avatar
0 votes
0 answers
21 views

pytest-django ERROR django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured

I have a Django project with pytest and pytest-django packages. I have an app "api" with tests/ folder with all of my tests. After running pytest in the terminal, I get an error: ============...
hifichevymane's user avatar
0 votes
0 answers
46 views

Jest error : SyntaxError: await is only valid in async functions and the top level bodies of modules [duplicate]

export default class TestClass { static async fetchFile () { try { const res = await fetch( url.to.file ); if (!res.ok) throw new Error( 'Something ...
SylO's user avatar
  • 1
0 votes
1 answer
22 views

SftpClient Unit test derived class and mock base class C#

I have a wrapper around Renci.SshNet.Sftp.SftpClient. I want to unit test this wrapper. my wrapper public class MySftpClient: SftpClient, IMySftpClient { public MySftpClient(string host, int port, ...
Mihai Socaciu's user avatar
0 votes
0 answers
31 views

I need a way to Unit Test my command handlers in asp.net core 6

This is my Unit Tests file. using FluentValidation; using Microsoft.Extensions.Logging; using Moq; using QueryStore.Application.Common; using QueryStore.Application.Queries; using QueryStore.Domain; ...
Hardik Dhuri's user avatar
0 votes
0 answers
20 views

I have a question about errors that occur due to specifying arguments in Unit Tests

I am creating and running unit tests for a class that implements a use case for searching geography. search_location_usecase_impl.dart class SearchLocationUsecaseImpl implements SearchLocationUsecase {...
sub's user avatar
  • 137
0 votes
1 answer
15 views

Value range "Unit" testing

Unit testing frameworks such an xUnit or GoogleTest make it easy to run a suite of tests, and with IDE integration you are only a couple of clicks away from having a full debugging session running on ...
Zachary Vander Klippe's user avatar
0 votes
0 answers
14 views

How to create a Unit Test to access Views in c#

Im new to create a Unit Tests for Service class. Im facing an issue in accessing views in my context. I have a two contexts one for writing and one for reading.Below are the sample for the context ...
SaranyaR's user avatar
0 votes
0 answers
30 views

JavaScript enum object cannot be read [closed]

In MBTICategories.js file, I defined an enum with the following code: const MBTIFeatureCategories = Object.freeze({ E: "Extraversion", I: "Introversion", N: "Intuition&...
Jieke Wei's user avatar
  • 173
0 votes
1 answer
44 views

test method returns Null Exception using XUnit

We are using CQRS/Mediator patterns, I'm trying to write some unit tests for the APIs, I started by the controllers. this is the method CreateAync() that I want to write unit test for. [HttpPost] [...
Wahéb's user avatar
  • 551
-1 votes
0 answers
10 views

How do I make sure that I'm mocking correctly in Jest unit tests in my app?

So I'm working on unit tests for the api endpoints in my app right now. Let's say the endpoint I'm testing is get-user.ts. It relies on certain other modules within my app, the most notable of which ...
areej's user avatar
  • 9
0 votes
0 answers
6 views

VTU not reading props object passed to the mount() function

When mounting a component with props object, VTU does not read props from the options object passed to the mount() function and therefore the test always fails. Otp.vue <template> <div ...
Achraf FAWZI's user avatar
0 votes
1 answer
17 views

How can I assert error values in ballerina?

I have a error type as defined below, type ErrorDetails record {| string message; string reason; "HIGH"|"MEDUIM"|"LOW" severity; int code; record {} ...
Lakshan Weerasinghe's user avatar
1 vote
2 answers
42 views

Python mock and call assertion

I am trying to write a python unit test to assert that a scoped_session .commit() is called. main.py from database import DBSession def deactivate_user(user_id): db_session = DBSession() user ...
user7692855's user avatar
  • 1,584
0 votes
2 answers
44 views

Mocking the Kotlin SupabaseClient for unit testing

TLDR : Here is a minimally reproduceable example. You do not need a Supabase account / database to get the error. I have some code like this, which performs some simple transformation of data before ...
jlengrand's user avatar
  • 12.2k
0 votes
1 answer
12 views

Sprng batch stepscope reader test with Mockito - org.springframework.batch.item.ReaderNotOpenException: Reader must be open before it can be read

I am testing @stepscope JDBCCUrsorIteamReader but getting below error. I am opening the reader before start reading but still its giving reader is not opened. I want to mock database calls. How can i ...
Pinki Sharma's user avatar
-1 votes
1 answer
29 views

Mocking nested promises with jest

The function that I am creating a test on uses a nested promises and cannot be converted to async await right now exports.createCampaign = (req, res) => { const { name } = req.body; User....
Ryan Garde's user avatar
0 votes
0 answers
32 views

Can I write behavioural unit tests using "Given-When-Then" in Pytest (Python)?

We currently have many unit tests in Python and we're using Pytest. Ideally I'd like to stay with Pytest as that's what the company has elected to be their testing framework of choice. I wonder if ...
Leslie Alldridge's user avatar
0 votes
0 answers
38 views

Unit testing an async function in Swift

I am trying to test an asynchronous function in my swift project and I am receiving this error -> Thread 1: "Task created in a session that has been invalidated" on the second to last ...
John Citrowske's user avatar
0 votes
0 answers
16 views

How to integrate C++ tests into a sckit-build pybind module

I'm making a python module based on the official pybind scikit build example. I (and the example) have some unit tests for the python part in tests, that runs with pytest. In my case, I have some ...
sodiumnitrate's user avatar
1 vote
0 answers
26 views

How can I properly test DateTime in my service?

I am having difficulties on how to test my service properly, as it uses DateTime. From what I have read, everything I need to do is to "isolate" the "collaborator" and a good way ...
John Doe's user avatar
0 votes
1 answer
37 views

How to mock the system clock for tests in spring boot applications?

I have the following static function: public static String formatTimestamp() { TimeZone timeZone = TimeZone.getTimeZone("UTC"); DateFormat dateFormat = new SimpleDateFormat("...
Ahmed Tharwat's user avatar
0 votes
0 answers
12 views

Cuckoo custom matcher failure message

I use Cuckoo for mocking and stubbing. Is there any way to improve failure messages if custom ParameterMatcher fails? Let's say (for sake of simplicity) I want to create a custom matcher for [...
Neru's user avatar
  • 679
0 votes
1 answer
47 views

Creating a DateTimeProvider bean for mocking

I need to write some tests for a JPA service that is creating/updating an entity. In order to properly test the 'createDate' field, I need to mock the DateTimeProvider that JPA is using so that I can ...
pbuchheit's user avatar
  • 1,387
0 votes
0 answers
19 views

Unit testing ViewModel functions that calls other suspending functions within a viewModelScope

I'm trying to test a ViewModel whereby it contains a function that calls another suspending function of a library, then assign its return value to an internal state. I want to uni test this function, ...
kak's user avatar
  • 81
1 vote
1 answer
27 views

unit testing a pipenv project in VSCODE

I was doing a simple unit test with unittest, and my *_test.py goes like: import unittest import pdf_text_extract import re class TestPdf2TxtMethod(unittest.TestCase): def test_txtextract(self): ...
Jianing JIA's user avatar
1 vote
1 answer
19 views

Mocked methods with Moq not getting called within code in Unity Play Mode Tests

If I mock a method, do I have to explicitly call that method to run my mocked implementation? I'm trying to get mocking to work inside a Unity project. I'm basically starting a scene and within a ...
P-ratt's user avatar
  • 261
-4 votes
0 answers
45 views

How to fix the unit test? [closed]

I'm trying to create a List of expected LocalDates in the sorted order manually. Then I loop through the sortedList using a for loop while asserting if the persons DOB corresponds with the expected ...
Magz_k's user avatar
  • 1
0 votes
0 answers
4 views

Integration tests compatibility Android with bitrise

I would like to start writing integration/unit tests and integrate it with bitrise. What are one of best options? Basically I could use one of the libraries i.e. AndroidX Test for unit testing and use ...
christianalready's user avatar
1 vote
1 answer
57 views

My unit test cannot cover yield return function [closed]

This is the class to test: public class TestClass { public IEnumerable<int> GetInt() { yield return 1; yield return 2; yield return 3; yield return 4; ...
Charla's user avatar
  • 89
1 vote
1 answer
20 views

How to return ResponseEntity when mocking RestTemplate

following is my method which I am trying to unit test public class Emp { public String getName() { ResponseEntity<LinkedHashMap> res = restTemplate.postForEntity(url, null, LinkedHashMap....
sachin p's user avatar
0 votes
2 answers
40 views

How to unit test VUE 3 Composition API methods?

How to unit test methods in VUE 3 Composition API (using vitest (preferably) or jest), knowing that methods are not accesible/exportable directly from the <script setup lang="ts"></...
Sinisa Rudan's user avatar
-1 votes
0 answers
65 views

When I try to test my program in Python from PowerShell, it gives a permission error [closed]

I started to learn Python like a month ago. While I was learning unit tests, we coded a calculator like this (this files name is calculator.py): def main(): x = int(input("What's x? ")) ...
erennnn's user avatar
1 vote
0 answers
45 views
+50

How to create a widget test that uses go_router's StatefulNavigationShell

I'm trying to write a widget test for a screen that uses go_router's StatefulNavigationShell, but I'm having trouble mocking the router and getting the expected results. This is the screen that uses ...
Arnoodles's user avatar

1
2 3 4 5
1697