Category "unit-testing"

Mocking moment() and moment().format using jest

I'm unable to mock moment() or moment().format functions. I have states where, currentDateMoment and currentDateFormatted are getting set as below. currentDateM

Mocking moment() and moment().format using jest

I'm unable to mock moment() or moment().format functions. I have states where, currentDateMoment and currentDateFormatted are getting set as below. currentDateM

How to write a unit test for spring specification?

I created a builder class which construct Specifications object. It is used for creating queries for JpaSpecificationExecutor. The builder is used, because I ha

Cmocka - should we all be creating one executable per test for isolating static variables?

Failure Given the following cmocka test with a static variable in a dependency: main.c #include <stdarg.h> #include <stddef.h> #include <setjmp.h

Jest: Better way to disable console inside unit tests

I wonder if there is a better way to disable console errors inside a specific Jest test (i.e., restore the original console before/after each test). Here is my

google mock - can I call EXPECT_CALL multiple times on same mock object?

If I call EXPECT_CALL twice on the same mock object in the same TEST_F . . . what happens? Are the expectations appended to the mock object or does the second

Spy on the result of an Observable Subscription with Jasmine

I am Jasmine unit testing an angular component, which uses Observables. My component has this lifecycle hook that I am testing: ngOnInit() { this.dataService.

Debugging Go tests in Visual Studio Code

On my Windows machine, I have Visual Studio Code installed. To run tests manually, I go in console to projects folder and enter go test main_test.go It works

how to prevent jdbc from trying to connect to a mysql database during unit testing

I'm making an application for a school project, but I'm running into the issue that when I try to run the unit tests that it tries to connect to the database wh

Is there a way to get unit coverage percentage (eg from jacoco) on only new code?

My hypothethical scenario is this: I have run my junit tests and generated a jacoco file my git diff shows I have changed 10 lines of code Now the intersection

Is there a way to get unit coverage percentage (eg from jacoco) on only new code?

My hypothethical scenario is this: I have run my junit tests and generated a jacoco file my git diff shows I have changed 10 lines of code Now the intersection

Jest 27: How to reset mock for jest.spyOn(window, "setTimeout")?

I am updating a project from jest version 26 to jest version 27. As part of the update I had to switch from assertions on setTimeout to assertions on jest.spyOn

Mock final class with Mockito 2

I'm removing Powermock from the project I'm currently working on, so I'm trying to rewrite some existing unitary test only with Mockito (mockito-core-2.2.28). W

matching List in any order when mocking method behavior with Mockito

I have a test using Mockito that has a very strange behavior : it works in debug but fails when running normally. After some investigation, I realized it's beca

How to test my update method with Mockito

Here is my test Class: @RunWith(SpringRunner.class) @SpringBootTest public class UpdateRestaurantTest { @MockBean private RestaurantRepository restaura

Comparing LocalDate using Hamcrest in Junit Test Case

I am my unit testing my REST Controller, one of whose field is LocalDate in my Test Case. Code below: @Test public void getByExternalTransactionId() throws E

How to mock Pipe when testing Component

Currently I am overriding providers to use mocked services like this: beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { tcb.ove

How to simulate "No Internet Connection" in Unit/Integration test in C#

I have a component that (by part) uses an internet connection. I wrote some UnitTests to ensure that to component is working. However, I would like to test the

How to use unit testing if there are multiple outputs in java?

How can I test a class that returns the Fibonacci series? I used an iterator for this code. The FibonacciIteratorTest class is below. public class FibonacciIter

How to unit test a component that depends on parameters from ActivatedRoute?

I am unit testing a component that is used to edit an object. The object has an unique id that is used in order to grab the specific object from an array of obj