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.

-2
votes
0answers
34 views

Equal strings failing test

I'm having a problem with one my unit tests where the expected string and the result string are exactly the same, yet the test is failing and saying they're different. This is the code for the test: ...
0
votes
0answers
8 views

DispatchEvent() is not working for ion change

I newly started writing Unit Test for my Ionic(3.9.2) project. I need to select an ion-option using the spec file. But throws error. ```file.ts this.NameArr = ["Mark","David","Josh"] ...
4
votes
0answers
39 views

How to test the pytest fixture itself?

What is the proper way to test that the pytest fixture itself. Please do not confuse it with using fixture in tests. I want just tests the fixtures correctness by itself. When trying to call and ...
0
votes
1answer
12 views

Is there a way to test a double value like near in gtest

I'm unable to find a proper way to test a double value in the unit test library test from google. test("circle > constructor", () { var s = circle(vector(0, 0, 0), ...
0
votes
0answers
19 views

Entity state gets changed to detached - In Unit Testing using EF Effort

Using EF Effort, am trying to perform unit test for my repository layer code, It does works for transactions and entity state. But in some cases, it throws this exception : System....
0
votes
0answers
26 views

Mocking localstorage in angular 7

I'm using localstorage in my application. The application works fine. I wrote test cases by mocking the localstorage like given below describe('#AppComponent', () => { ... const store = {}; ... ...
1
vote
1answer
37 views

using assertions in an unordered collection

I'm inserting a Collection<Event> inside a table, something like this Collection<Event> eventCollection = service.insert(events); Now, I need to test that Events in eventCollection has ...
0
votes
1answer
45 views

Testing a Redux login Action with fetch api

On my React-Native project, i tried to start unit testing, how to test on Redux action that involves a login fetch api call.I've looked at some examples of testing an async Action, but I haven't ...
0
votes
1answer
24 views

How to Inject 'Microsoft.Extensions.Configuration.IConfiguration' using AddTransient Method in XUnit

I am trying to Unit test a method which in in class TWService and require two dependencies to Inject i.e IXMLResponseSave and IConfiguration. I am able to inject dependency for IXMLResponseSave using ...
0
votes
1answer
11 views

how to write unit test for catching the exception that exception throw in asynchronous block (observable or promise) in a function?

I want to write unit test for this function getData(). getData(){ this.service.getvalues().subscribe( results => { }, err => { throw err; } ); }...
0
votes
0answers
24 views

How to write unit tests in spring boot for elasticsearch

I have to write unit tests of spring boot application with elasticsearch. I've read a lot of documentation, and I've discovered that an embedded elasticsearch can be used, a bit like using H2 for ...
0
votes
1answer
34 views

Null Pointer exception passed by test method

Method that needs to be tested - located in AnalyticsServiceImpl.java class public void trackSplashState(MeasurementViewEnum measurementViewEnum) { HashMap<String, Object> data = ...
0
votes
0answers
13 views

Unittesting in Vala

I've now written a few unittests using GLibs inbuilt unit tests, in Vala. That means everything is done as: class test_some_class{ static void main(string[] args){ Test.ref(args); ...
0
votes
1answer
12 views

How do i mock and customise the values of a function imported from a npm package using Jest?

I use isMobileOnly from "react-device-detect" npm package in my React component say(SampleComponent.js). I would like to customize the return value of isMobileOnly in my jest unit tests. I have ...
0
votes
0answers
8 views

Unit testing for object initialization method in angular 7

I need to write unit test case for the below TS method. I don't know how to initialize the new object in TS. help me to update for the same. TS : CreateObjectInitialisation() { this....
1
vote
0answers
23 views

How to stub an independently exported helper method

I have a component called Dashboard. In componentDidMount life cycle method, I'm calling an async helper method. Now in my unit test, I was trying to stub the same method to verify both method call ...
0
votes
1answer
20 views

NodeJS unit testing

Possibly a naive question but I have a class similar to(mine has more data read from database and caching them): var genericClass = class { constructor() { this.genericStructure = {}; ...
0
votes
1answer
31 views

Unexpected result from unit testing CRUD methods from Service layer

I'm trying to unit test the crud methods from my service layer, I've wrote the correct code (I think) but AssertTrue gives me the opposite result I was expecting.(java.lang.AssertionError:) My test ...
0
votes
1answer
23 views

How to unit test Stream.listen() in Dart

Consider the following test code ... main() { StreamController controller; setUp(() { controller = StreamController.broadcast(sync: false); }); tearDown(() { controller.close(); });...
0
votes
1answer
43 views

How to test this Camel Route? Dependence Injection and Enviroment Variables

I have two doubts: a. How to mock the http4 compoenent in a way that my route does not know when it is mocked and when it is real? b. How to initialize myDestinationEndpoint when running tests? ...
0
votes
0answers
11 views

Django tenant unit test return 403 instead of 200

I have an application in django 2.1 and I am using a django-tenants package. I have application accounts there, which in settings.py is in SHARED_APPS. I want to write a unit test for the login view. ...
-1
votes
2answers
22 views

Python assertEqal string - ignore part of it

I'm using python 3.6.7 In tests, I'm using assertEqual to compare string objets. Those strings contain some time data. since this data is different from test to test, I want to ignore this data. Is ...
0
votes
0answers
18 views

Cannot find module 'expo-react-native-adapter' from 'setup.js'

When I am running the test suite on the react-native code of my Expo App, I get this: But I don't understand why this is happening. The testing was working fine yesterday. This is the test code: ...
0
votes
0answers
40 views

Mock fields in a class?

I wish to unit test classes that contain fields. Because of the fact that it is unit tests, all dependencies should be mocked. Let's say that I have the classes public class A { public B b = new B(...
-1
votes
0answers
17 views

How to define wstring ToString<vector<unsigned char, allocator<unsigned char> > >(const vector<unsigned char, allocator<unsigned char> >& uc)

For some reason the C++ compiler throws an error in this line Assert::AreEqual(vector(), vector()); I have tried implementing these two functions without success. template<> template<...
0
votes
0answers
17 views

Python mocking class instantiation and accessing private member variable

I want to test a method inside a class which updates the value of a member variable. However class takes constructor arguments which are not required in the method to test. class SimpleClass(Database)...
0
votes
1answer
32 views

What defines an “isolated” test?

I have a class called Customer and I wish to unit test this class and its public interface. To be able to unit test, I have to test Customer in isolation from its real dependencies. Other than ...
0
votes
1answer
11 views

Mockito: argThat for methods taking multiple arguments

I am trying to use Mockito's argThat API: verify(mockService).methodA(argThat((List ids, int b) -> ids.get(0).equals("123"))); mockService has methodA which takes two parameters: a List and a ...
1
vote
0answers
15 views

Run function/behaviour after all behaviours ended in Pony

I have a simple Publish-Subscriber that I want to write tests for. The methods called here are all behaviours, except get_number_consumed_messages that would be a function. class iso _SinglePubSub is ...
1
vote
0answers
21 views

Testing custom hook and getting "Warning: An update to TestHook inside a test was not wrapped in act

EDIT: I found a solution, coming from this video from Kent C. Dodds. Just wrap the jest.advanceTimersByTime calls in an act function. So this: jest.advanceTimersByTime(510); becomes: act(()=>...
1
vote
0answers
25 views

How to unit test the firebase connection when code is written in Bloc-pattern?

I have written my code n Bloc pattern based on this article. In my code, I need to connect to a real-time database and fetch some data from it. But unfortunately, I can't write a bug-free unit test ...
0
votes
1answer
13 views

AVA unit tests fails passed Javascript test specs

I am currently working with ES6 modules with .mjs extensions and creating test cases for some functions. I have chosen AVA due to its support of this extension type but the test executions are not ...
0
votes
1answer
22 views

Get an Error “Expected spy <functionName> to have been called” in angular 6 jasmine

I have a method "onEdit" in a component. In that method I've called service method "getAttributeById", I am doing a api call in "getAttributeById" service method and return an observable and I am ...
0
votes
0answers
19 views

Angular Test - editing non related files causing other test suites test to fail

I have an test suites which test a specific component (component A) , I am using the fakeAsync and tick to test the component whether it has call a servicd function using spyOn. The test results is ...
0
votes
0answers
20 views

How to write Android unit test for fetching image using content resolver?

I am a beginner in Android unit testing. I wanted to write unit test for the following code. I am not able to find a way to mock an image for using in the test. Please help. fun ...
0
votes
1answer
29 views

Cannot reproduce my travis-ci unsatisfiable requirements julia error locally

I have a Julia project configured to run unit tests in travis-ci and I got a Pull Request from someone else. Tests are passing for julia 0.7, but not for julia 1.1. I am getting an error related to ...
-5
votes
1answer
42 views

How test if defer is called or not

I have following code func (s *MyRepo) InsertOrder(ctx context.Context, orderID string) error { query := `INSERT INTO orders (orderID) VALUES (?)` stmt, err := s.db.RawDatabase()....
0
votes
0answers
22 views

Angular Unit Testing using Mock Models

I am trying to unit test a component. I need to set a variable on that component to an instance of PolicyMock, which is a mock I created from a model. Example of Policy (real model) export class ...
0
votes
0answers
20 views

How to write unit tests for kotlin coroutines

I am trying to unit test the kotlin coroutines. My project is following MVP pattern where the coroutines are used in the presenter like this: fun authenticateWithUserAndPassword(usernameOrEmail: ...
0
votes
2answers
17 views

How can I assert that a function passed to a class constuctor is passed by reference and not duplicated when using composition?

In the code below I can easily assert that zombie is an instance of Zombie. When zombie is created the function bitmapRenderer is sent to it and becomes the function render() inside `Zombie'. I am ...
-1
votes
0answers
21 views

how to unit test a method using OAuth authorization server provider

In my code, I'm resolving autofac dependancies as below. public class OAuthTokenProvider: OAuthAuthorizationServerProvider { private readonly IContainer _container; public ...
0
votes
1answer
51 views

spring boot : how to run a test class only on jenkins?

We have a test class which I'd like to run only on Jenkins. I think this can be achieved by checking the active spring profile (such as jenkins) or when the local machine name is XYZ. The issue is, ...
0
votes
0answers
50 views

Write a Unit Test For a StackOverflowException

I have a bug that occurs in a low-level system under rare circumstances which results in a StackOverflowException. I've written a test that reproduces the bug, but the test can never run to completion,...
0
votes
1answer
27 views

Why viewChild reference on Angular 8 unit test is undefinded

I am using Angular 8 in my project but I have a problem with the unit-test when I have a component with ViewChild Ref in the unit-test is undefined. any help I have one component @Component({ ...
1
vote
0answers
23 views

How to fix NoSuchMethodError on startKoin() method

I'm trying to launch tests with Koin DI help like in the example https://insert-koin.io/docs/2.0/documentation/koin-core/index.html#_making_your_test_a_koincomponent_with_kointest or https://insert-...
0
votes
0answers
19 views

Module 'io' has no attribute '_WindowsConsoleIO'

I'm trying to get pytest to run on a Windows PC. It's working fine on one machine but another is giving an error even when I just try pytest.exe --version. The machine that works is a Windows 10 ...
0
votes
0answers
10 views

Phpunit coverage-text is not displaying all classes files tested

I'm running phpunit in my project but the coverage-text is not displaying all the classes inside the folder in whitelist. I've tried with PHPUnit 7.5.12 and PHPUnit 8.2.1. I've tried with PHP 7.2 ...
0
votes
0answers
7 views

Dart mockito, verify that one of two possible calls chains was performed

Imagine I am unit-testing Meyers diff algorithm implementation: I have [1, 2, 3, 4] as a first data snapshot and [2, 1, 4 ,3] as a second. The implementation itself dispatches updates to some listener,...
0
votes
1answer
12 views

Unit testing: How do I mock the innerWidth property on the window object with Angular + Jasmine?

I want to write a unit test which expects a variable to contain a specific value depending on the innerWidth of the window. In my unit test, I use window.innerWidth = 1000;. However, I receive an ...
0
votes
0answers
18 views

Jest/Enzyme ReactNative how can I test the state in a functional component

I have a functional component which use useState in it. How can I test its state through jest? I tried: test('Test state', () => { const wrapper = shallow(<MyComponent {...props}/>) ...