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
Filter by
Sorted by
Tagged with
1 vote
2 answers
1k views

Jest: Object value within toMatchObject method is array and check have length (not empty)

I writing Jest tests with .toMatchObject() and have the following problem. Some of my object's values are arrays, and I want to test do they have length or empty. My code right now: test('suite one', ...
243 votes
6 answers
297k views

Assert an object is a specific type

Is it possible in JUnit to assert an object is an instance of a class? For various reasons I have an object in my test that I want to check the type of. Is it a type of Object1 or a type of Object2? ...
0 votes
0 answers
7 views

How to Run Azure DevOps pipeline on Databricks using Serverless cluster instead

I am writing an Azure Devops pipeline to run Unit Tests with nutter on Databricks. As described in the nutter documentation, this is the code to run the tests: nutter run /Shared/ $CLUSTER --recursive ...
0 votes
0 answers
12 views

Alternative methods for testing Laravel job dispatching in unit tests

I'm writing unit tests for a job's login functionality in Laravel. However, when I attempted to dispatch the job using Job::dispatchSync, it seemed that the job wasn't executed. Upon further ...
11 votes
5 answers
9k views

How can I use FakeItEasy with HttpClient, in a unit test?

I'm trying to figure out how to use FakeItEasy with the HttpClient, given the following code: public Foo(string key, HttpClient httpClient = null) { .. } public void DoGet() { .... if (...
10 votes
3 answers
6k views

'Toolkit not initialized' exception when unit-testing an JavaFX application

When I try to perform unit tests on components which contain JavaFX controls I get a java.lang.IllegalStateException: Toolkit not initialized. How can components be unit tested which operate with ...
-2 votes
0 answers
14 views

Database sur les test [closed]

I'm looking for existing examples of unit and integration tests in open-source projects that can be used to train an AI model. If anyone knows of such examples, please share them with me. I'm looking ...
0 votes
0 answers
11 views

Disposing of docker containers causes integration test process to not complete

for my integration tests i use Xunit and docker containers. In the constructor of the test class i initialize an ApiFactory. Inside the api factory i create containers for PostgresSql, Redis and ...
0 votes
0 answers
29 views

How to modularize dependent unit tests in Python

Here is a hypothetical composite unit test. It calls two algorithms, checks some properties of the results independently, and then compares them to each other. class MyTestCase(unittest.TestCase): ...
0 votes
1 answer
18 views

Asserting attribute change after transaction, using Foundry test network

Context I am trying to test whether a function receiveInvestment() external payable { that receives currency from a wallet address private _investorWallet; changes the uint256 private _someStoredValue;...
7 votes
1 answer
955 views

How to aggregate test reports in android multi-module gradle project in 2019

I have a multi-module Android gradle project. project |- app |- module1 |- module2 Each of the modules contains unit tests, the app module also contains Instrumented Tests. Instead of taking ...
0 votes
0 answers
6 views

Mocking GraphCypherQAChain in Python unit test cases

chain.py ---------------------------------- from langchain.chains import GraphCypherQAChain from langchain_openai import ChatOpenAI from langchain_community.graphs import Neo4jGraph from langchain....
1 vote
1 answer
21 views

System.ArgumentException: Can not instantiate proxy of class: Atlassian.Jira.Jira - How to write Unit Tests for JIRA Services in .NET?

I have this Service which is responsible for fetching and creating JIRA tickets. public class TcJiraService(Jira tJiraClient, IOptions<TcJiraOptions> tOptions, ILogger<TcJiraService> ...
2 votes
1 answer
671 views

Mocking fetch POST

I am writing test case for below function: handleShare(response, payload) { ShareUtils.listUsers() .then((users) => { users.forEach(user => userList.push({ ...
0 votes
0 answers
14 views

Properly mock firebase-admin on jest

I have an NX monorepo with jest and node. I would like to add some unit testing to some code I have and I am required to mock firebase-auth. I created the following mock under lib/src/__mocks__: ...
0 votes
0 answers
59 views

Calling a function throws an exception only when running as a unit test [closed]

I have two methods Parse and FormatString. I did remove all the irrelevant code which is not needed in order to reproduce my problem. If I run the code in normal mode everything works as expected. If ...
1 vote
3 answers
1k views

How to avoid "RuntimeException: My id 0 not in the peer list" when starting embedded Zookeeper?

I'm trying to start a zookeeper node with QuorumPeerMain.runFromConfig in a BeforeAll method so that I can use it in tests (it's embedded in the same JVM). I'm getting Invalid configuration, only one ...
0 votes
1 answer
32 views

Link against a Visual Studio executable project, for unit testing, with C++ modules?

Microsoft docs here describe how you can, in Visual Studio, create a unit test project and connect it to an executable project, in order to unit test the code in that executable project. My problem is ...
13 votes
5 answers
13k views

Unit tests not discovered in Visual Studio 2019

The tests are present at Test Explorer but run command has no effect. Looking at Output windows, for Test outputs it shows many errors like this: MSTestAdapter failed to discover tests in class '...
-1 votes
1 answer
18 views

GitHub Autograder Tasty Handle Writing Exception

I'm unit testing the following Haskell function in Tasty for GitHub's autograder: countLetters :: IO [Int] countLetters = do putStr "First entry: " x <- ...
2 votes
2 answers
54 views

JUnit code coverage switch statement with default branch

I have util method to process some text. The way of processing is determined by enum Mode. While writing unit test to cover this method, I had to add dummy enum element in order to include default ...
106 votes
3 answers
71k views

How to test an exception was not thrown with Jest?

The Jest docs do not demonstrate a way of asserting that no exception was thrown, only that one was. expect(() => ...error...).toThrow(error) How do I assert if one was not thrown?
1 vote
1 answer
33 views

Error NU1301: Unable to load the service index for source

Background I am troubleshooting the build pipeline of a greenfield project. Everything worked correctly before, recently I added a nuget package that comes from the same internal Artifacts Feed. To be ...
5 votes
4 answers
17k views

Junit: assert that a list contains at least one property that matches some condition

I have a method that will return a list of objects of type MyClass. MyClass has many properties, but I care about type and count. I want to write a test that asserts that the returned list contains ...
0 votes
1 answer
41 views

I get the Error CS0104 'Assert' is an ambiguous reference between 'NUnit.Framework.Assert' and 'Microsoft.VisualStudio.TestTools.UnitTesting.Assert

I am currently making a simple unit test for my Recipe storage application to test my calorie calculation. However, I keep running into the above issue and am unsure as what I can do to solve it. The ...
1 vote
1 answer
24 views

Angular 16 route guard unit test observable createSpyObj property

Trying to familiarize with unit testing a route guard. I have a relatively straight forward guard that gets a value from a subject asObservable to either createUrlTree or return a boolean value. In ...
-1 votes
0 answers
25 views

How to install automotive_dlt package on Ubuntu 20.04.5 LTS [closed]

I am trying to run unit test for my application it required automotive_dlt package. when I try to install it, it throws an error as shown below Reading package lists... Done ...
1 vote
1 answer
4k views

Cannot instrument class XXX because it or one of its supertypes could not be initialized

Because jdk17 not compatible with, so i change to mockito 4.9.0. And that leads to @SuppressStaticInitializationFor will can't be used, but i need some classes not initialized statically @RunWith(...
0 votes
2 answers
278 views

Is there a Automocker.CreateInstance equivalent in NSubstitute?

When I need to create an instance of a complex object, such as a large service, with Moq, I can achieve it using the following approach: //Mocks and Setups needed var autoMocker = new ...
326 votes
43 answers
419k views

No tests found for given includes Error, when running Parameterized Unit test in Android Studio

I have tried to run Parameterized Unit Tests in Android Studio, as shown below: import android.test.suitebuilder.annotation.SmallTest; import junit.framework.TestCase; import org.junit.Test; ...
0 votes
0 answers
15 views

Angular 14 - To test method public date in Jest

I need to test this public method of my Angular component in Jest: getMinDateIniPicker(): Date { const dataControl = this.form.get(CATALOG_INPUT.DATA) as AbstractControl; this....
0 votes
2 answers
940 views

mocking AudioContext() in Jest

I have the following code inside a function in my project; .... if (state.context == null) { return { ...state, context: new AudioContext() } } .... I'm trying to test this ...
224 votes
20 answers
81k views

How can I unit test Arduino code?

I'd like to be able to unit test my Arduino code. Ideally, I would be able to run any tests without having to upload the code to the Arduino. What tools or libraries can help me with this? There is ...
54 votes
8 answers
44k views

Rails - How do you test ActionMailer sent a specific email in tests

Currently in my tests I do something like this to test if an email is queued to be sent assert_difference('ActionMailer::Base.deliveries.size', 1) do get :create_from_spreedly, {:user_id =&...
6 votes
1 answer
242 views

Unit testing for URLSessionDelegate method - Swift

I have a custom delegate class called CertificatePinningDelegate which conforms to URLSessionDelegate. I'm using the delegate method urlSession(_ session: URLSession, didReceive challenge: ...
-1 votes
0 answers
14 views

Unable to access element in Test Dom in Jest

I am unable to access a dropdown in Test Dom, and I can clearly see the element in Test Dom. Note: I'm not able to access this dropdown only when isDisabled is false. As soon as the disabledCondition ...
0 votes
1 answer
39 views

C# Visual Studio run unit tests conditionally

I've to unit test some library features involving SSH communication with both Linux and Windows servers. I have a test_config.json file provided by the user. This config mainly contains two properties:...
0 votes
0 answers
14 views

How to test React Functional component context api with enzyme

Hi I am using react functional component and I have almost covered all the test cases which works fine until I added one line if code which uses the state value from my context api provider. ...
9 votes
2 answers
4k views

How to skip a Unit Test at runtime?

We have some Automation tests using the selenium web driver which are great and provide a really good regression pack. The problem is now we have feature toggles in our code. So I need to say ignore ...
0 votes
0 answers
14 views

Using secrets for bdd test cases

I've written bdd test cases for my application and for that, I want to use secrets.json values for ClientId and ClientSecrets. I'm using msal approach to generate clientid and clientsecrets.I've also ...
-1 votes
0 answers
15 views

@Context not injected on Resteasy Unit test

I have unit tests using mocks and MockDispatcherFactory to test my Rest app. These were working with previous versions of Resteasy, but when updated to 3.15.0.Final (Wildfly 24), @Context objects are ...
2 votes
1 answer
828 views

Mock python k8s client

Here is my snippets: folder structure utils/ ├── __init__.py ├── k8s_client.py ├── simple.py └── tests ├── k8s_client_test.py k8s_client.py import os from kubernetes import client, config config....
0 votes
2 answers
31 views

Best practice for writing unit tests for Quarkus Panache entities

I'm working on a project using the Quarkus framework, and I've implemented some entities using Quarkus Panache for my data persistence layer. Now, I'm trying to write unit tests to ensure the ...
0 votes
0 answers
15 views

C# UnitTest AutoMapper when using IValueResolver - Mapping crashes

I'm trying to test a method with a Mapping. Method I'm trying to test: return _mapper.Map<IEnumerable<EinsaetzeDto>>(einsaetze); I always get the same error: Destination Member: ...
0 votes
0 answers
12 views

Custom matcher in vitest exception: Failure cause not provided for

I'm using Vitest and I wrote simple custom matcher in my setup file: import { expect } from 'vitest'; expect.extend({ aaa: (received: number, expected: number) => { const pass = received ...
52 votes
7 answers
147k views

Using Jest to mock a React component with props

I have a React component which contains some other components that depend on access to a Redux store etc., which cause issues when doing a full Enzyme mount. Let's say a structure like this: import ...
0 votes
0 answers
12 views

Unit Test Case Error: No AppConfigProvider found in context

I'm trying to test a function in Dart that involves accessing configuration data from the context. The function call looks like this: context.typographyConstants. However, typographyConstants seems to ...
4 votes
1 answer
323 views

Angular Unit Test TypeError: this._renderer.addClass is not a function

After updating, my previously passing unit tests now fail with the error: 'TypeError: this._renderer.addClass is not a function' across multiple tests, despite not using or importing the renderer in ...
18 votes
2 answers
37k views

How to setup Request.Header in FakeHttpContext for Unit Testing

I have a FakeHttpContext I have been trying to modify to include some headers for testing purposes public static HttpContext FakeHttpContext() { var httpRequest = new HttpRequest("", "http://...
0 votes
0 answers
23 views

How to clean up test data beforeEach test [closed]

I have a bunch of unit tests for my Firebase cloud functions, they all pass when run in isolation but as soon as I run the entire test suite, I get failing tests. All of the tests fail for the same ...

1
2 3 4 5
1711