Newest 'unit-testing' Questions - Stack Overflow

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.

0
votes
0answers
6 views

How to unit test mongotemplate functions

I want to write unit test for mongotemplate function calls. I am not sure how to write that, I have seen instances of integration test case only on web. public Class customerById(String id) { ...
0
votes
1answer
20 views

What is the point of mocking the method of an external library when unit testing?

What is the point of mocking the method of an external library when unit testing? Let's say that I have a function that uses XYZ library to get the current user using a given authorization token, and ...
1
vote
1answer
39 views

Don't understand this “object not callable” error

I am setting up unit tests and when trying to call a function, Pt2D, I am getting the error TypeError: 'Pt2D' object is not callable. I have tried all other solutions on the first couple pages when ...
0
votes
1answer
13 views

Jest test does not fail on error while rendering

I'm trying to fix some unit test that passes regardless of what happens in the rendering. import React from 'react'; import Component from './Component'; describe('Basic component tests', () => { ...
0
votes
0answers
16 views

Powermock can't mock static class

I have a class with code similar to : public class class1{ private static final ConfigurationService config = Util.getInstance(ConfigurationService.class); private SendQueueMessages sender; ...
0
votes
0answers
9 views

Using Mockito to test deleting records from an HBase Table?

I am writing unit test cases for an offset management utility (table stores offsets of partitions along with their status, and I am fetching/updating when needed). To do so I need to mock a connection ...
0
votes
0answers
14 views

How to reduce the fragility of jasmine unit tests in angular?

Angular recommends using Jasmine for their testing framework, but the more I work with Jasmine the more I worry about the fragility of my unit tests. Currently, I am using stubs and spies to provide ...
1
vote
0answers
25 views

How to unit test js classes (objects) using Jest?

I am new in unit testing, and try to write the tests for my Express app, using Jest. I have a class, and as I understand, unit testing mean that I need to write test for every method, and isolate it ...
0
votes
0answers
14 views

Test async- Promise Jest

Trying to run a test for the following function: USING JEST AND ENZYME FOR REACT JS async patchAccount() { const { user, services, FirmId } = this.props; let StatusChanged = this.state....
2
votes
1answer
35 views

How can I mock a function called from a dictionary?

test.py: @pytest.mark.django_db def test_b_called(mocker): b = mocker.patch('app.service.b') service.a('b') assert b.called service.py: def a(type): _actions[type]() def b(): ...
0
votes
0answers
11 views

Overriding the core rand() function in PHPUnit only works when run in separate process

I want to use PHPUnit to test some edge cases on a function that calls rand(). My composer.json file has the lines: "autoload": { "psr-4": {"CashID\\": "src/"} }, "autoload-dev": { "psr-4": { ...
0
votes
0answers
13 views

Jest and React Native: How to mock AccessibilityInfo

I'm testing my react native app with Jest and the following line gives me an issue. AccessibilityInfo.announceForAccessibility(errorMessages[0]); Error: TypeError: Cannot read property '...
0
votes
0answers
6 views

Dynamic asynchronous mocha tests

I have a service class, which 50 other "services" extend. While each service has its own test, I would like to write a test suite for all of the services shared functionality (I have a method thing ...
1
vote
0answers
11 views

Testing Room as JUnit Test Not AndroidTest

Trying to test room migration using the MigrationTestHelper class and Robolectric. We want it as a JUnit test because our CI environment cannot fire up an emulator. (Please no answers with CI fixes ...
0
votes
0answers
12 views

How to limit FsCheck Prop.ForAll to get the value within the specific range

I want FsCheck to always pass in the list of long datatype but these long numbers should be between specific range e.g. 1000 - 9696969696. I know there is something called Gen provided by FsCheck but ...
-1
votes
0answers
7 views

How to use typescript in karma files

I am trying to provide some global function in my test cases, so that it will be available to all test cases. I have created on function file in type script and added it in karma.config.ts file ...
-1
votes
0answers
26 views

Why is the field not defined within an instance of a class?

I have tried to create a unit test to check that a method in a class in another namespace is working, however it does not seem to recognise the field grades from the Book class within this test class. ...
1
vote
1answer
15 views

How to write jasmine unit test case for the function to be called upon onerror of img tag

Below is the code I am using but this test case is getting failed //test case it('should display default image if the image link in people finder result doesnot exist', fakeAsync(() => { ...
0
votes
1answer
22 views

Generate unit tests on Android

Colleagues, I am having hard time to find a library/framework/etc... which could help me to generate unit tests in Android. I know that in Java there are multiple solutions, which could generate unit ...
0
votes
0answers
15 views

How to create a mock object in Scala?

I am writing the unit test for a Scala class, code is given below. Here I am trying to mock class B methods, when I am writing test methods for class A. This is what I tried: Test class for A class: ...
0
votes
0answers
8 views

_firebase.collections.collection.get.mockResolvedValue is not a function on vue

I'm trying to test the firebase collections, but I'm getting the following error: _firebase.collections.contacts.get.mockResolvedValue is not a function I'm using jest, and already tried using the ...
-1
votes
0answers
33 views

How to do unit testing on c# code by using unit test .net framework? [on hold]

I'm new to unit test. Previously I'm only develop software but didn't experience any unit test before. The following is example 1 of my function in my class. I would like to do the unit testing on ...
2
votes
1answer
38 views

Angular Unit Test: How to unit test .map()?

I need to test one of services method and I'm not sure about how to achieve 100% code coverage for parts of code that run as result of calling some injected service method. Service Method to be ...
0
votes
1answer
25 views

How to access the resource files that are kept under resources folder

How to get the absolute path of the files(cacerts.pem,client.pem,client-key.pem) that are kept under the folders as below in the image This is in the eclipse and gradle environment
1
vote
0answers
17 views

System.BadImageFormatException with Oracle.DataAccess and mismatch with AMD64

I'm building my project UnitTest vbproj on Visual Studio 2017 Professional. When I build with "Any CPU", there is one warning: warning MSB3270: There was a mismatch between the processor ...
1
vote
0answers
11 views

Is it possible to make enzyme work with RN + hooks?

I've got a project what used to be a normal React project (before the hooks hype). My stack for testing included jest + enzyme. Now want to move to hooks, but I can't make it work. For some reason ...
0
votes
0answers
34 views

How to test a websocket client-server interaction?

I'm writing an integration WebSocket layer for one service and would like to test the interaction between my code and the server by creating some integration type of tests. There's a project called ...
0
votes
0answers
13 views

What is the best way to test the output of a Grammar(is written in javascript)? How about the Mocha test?

I wrote a Grammar about traffic signs information (this information is in a text format) and used Antlr4 to generate a parser in JavaScript. Over time, my Grammar is getting bigger and more ...
0
votes
0answers
13 views

What are best practices for unit testing multiple functions that have very similar test scenarios?

Let's say I have two pure functions, pureFn1 and pureFn2. These functions must pass similar tests. describe("generic function", () => { it("should fulfill condition 1", testCondition1); it("...
0
votes
1answer
16 views

How should I Link multiple projects App.config file in one Test Project in C#?

I want to link multiple projects App Config file into my Single Unit Test Project in DotNet framework in C#, As I wanted to access the different config files for different test methods. Can anyone ...
0
votes
1answer
28 views

Angular Unit Test: How to mock properties in a method?

Here is the service that I am trying to test: @Injectable() export class BomRevisiosnsService { constructor( private baseService: BaseService, private appConstants: AppConstants, ...
0
votes
0answers
22 views

How to mock the removeChild or appendChild function call in angular directives testing?

I am facing issue in angular directive testing with mocking the dom manipulation api's removeChild or appendChild functions. directive is created to add/remove the items to dropdown menu. I have ...
0
votes
1answer
40 views

Unit testing a public method that calls multiple private methods

I want to test a public method that calls multiple private methods. What I read from all the answers to previously asked questions are varying. Some say if one encounters such situation, then probably ...
0
votes
0answers
20 views

Could not activate the component function by jasmine unit test

Could not activate my function within showCreateUserPanel Expect console.log and updateDefaultValue have been called Use By.css fetch the directive and activate the (create)="showCreateUserPanel()" ...
2
votes
0answers
18 views

Best Practices for Unit Testing Builder Objects?

There is great debate about whether or not setters/getters should be unit tested. Example Should unit tests be written for getter and setters? I believe that builder objects fall within the same ...
1
vote
2answers
29 views

Google Test: How to run fixture only once for multiple tests?

I am trying to test a http client using gtest. I want to test this client with my own http server. I have a small python server. Test cases would be client sending various requests to this python ...
-1
votes
0answers
14 views

Xunit Debug Acting Strange

I'm using Xunit for my unit tests. The application is using ASP.NET Core. I noticed some strange behaviors when I debug: Variables in the actual method (not the test method) shows null when it is not ...
1
vote
0answers
17 views

Unit testing coroutine with LiveData observer

I have a viewmodel which contains two livedata member variables and a method that uses coroutines to call out to an API. This all works fine running the app, my problem is when unit testing this it ...
0
votes
1answer
8 views

Php mocking a function outside of a class

The Mockery docs have examples for mocking classes and their members but I don't see any details for mocking included functions. I would like to mock the implementation for wp_send_json() which is ...
0
votes
0answers
13 views

How to assertequal an sql server and oracle dB with python?

Currently building test proof of concept for my company using python. The concept I want to build is about automated testing of our application. From generating data in database through our API and ...
1
vote
1answer
30 views

How to test async function with spyOn?

I am trying to test an async function in a react native app. class myClass extends React.Component { ... closeModal = async () => { if (someCondition) { await myFunction1(); } ...
-5
votes
1answer
27 views

How to implement a faker into my go test?

I am trying to learn Go and write my first test. I would like to figure out how to implement a faker to test CRUD on terraform. I've figured out how to import faker and created the variables to use. ...
0
votes
1answer
19 views

How to write unit test for code with if else statements based on config files

I have a function like the following: const config = require('../config') getLabel (objectList) { if (config.labeling.currentVersion === 'v1') { // Do something on objectList return true }...
1
vote
1answer
27 views

Flutter unit testing. error while running test

I am getting following error while running flutter unit test. 00:05 +1: ... /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart Shell: [ERROR:flutter/shell/...
0
votes
1answer
25 views

“Too few invocations” but method is invoked and everything is created using GroovySpy or GroovyMock

I have class like this: class A(B b, C c, D d, E e) { protected void doSth() { test(); } protected void test() { System.out.println("test"); } } and I am trying to test if ...
1
vote
1answer
25 views

Unit Testing Razor Pages that inherit from a BasePageModel

I have a Razor Pages app where several services are used by all pages in the site and have added those services to a BasePageModel, that I inherit from on each Razor Page. My BasePageModel looks ...
0
votes
1answer
15 views

Example of using multiple then in test Android

While learning android testing have figured out that I can use 'then' several times. But don't understand cases where it might be helpful. For example when(mockObject.add(any())) .thenReturn(true,...
3
votes
1answer
40 views

Error: Expected spy create to have been called

I'm writing unit test cases in angular 7 for a Component with async service and getting this error: Error: Expected spy create to have been called once. It was called 0 times. Here is my ...
1
vote
0answers
18 views

Not able to access the room database from test cases - Android

I am getting an error while performing the database operation. In my project when I try to access deleteAll() from Dao class ie.e,AuthenticationDaoof Room Database from my test cases I am getting ...
0
votes
0answers
9 views

sinon.match() dont match object with Json.stringify response

I am testing a simple express route that returns a json object and usin mocha with sinon to match the response. This is the simple express response /login const login = async (req, res) =...