ASP.net MVC: Where to keep application data?

I am just starting porting an application to ASP.net MVC and I have an object holding application state (it keeps track of certain processes running on the machine, starting and stopping as...

Casting interfaces for deserialization in JSON.NET

I am trying to set up a reader that will take in JSON objects from various websites (think information scraping) and translate them into C# objects. I am currently using JSON.NET for the...

Mocking MessageDigest.getInstance() to throw an exception

I got the following method: private MessageDigest getMessageDigest() { try { return MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new Error(e); } } To get...

Mockito Exception - when() requires an argument which has to be a method call on a mock

I have a very simple test case that is using Mockito and Spring Test framework. When I do when(pcUserService.read("1")).thenReturn(pcUser); I get this...

How do I mock a 'timeout' or 'failure' response using Sinon / Qunit?

I've had no problems sorting out mocking the success condition, but cannot seem to fathom how to mock the failure/timeout conditions when using Sinon and Qunit to test and ajax function: My set up...

How to mock/fake SmtpClient in a UnitTest?

I want to use it to fake System.Net.Mail.SmtpClient in a MS-Test UnitTest. Therefor I added a Fakes Assembmly of System.dll. Then I create a ShimsContext and a StubSmtpClient. using...

Code Coverage: Best practice on excluding non-testable code

We are currently discussing how to define our goals on code coverage in a C# project (this question is not limited to C# though). On the way, we found that we should exclude some code from being...

How to mock a redis client in Python?

I just found that a bunch of unit tests are failing, due a developer hasn't mocked out the dependency to a redis client within the test. I'm trying to give a hand in this matter but have...

Mocking DbSet<T> inline

I am using .NET4.5, EF6, and Moq for unit testing. I am trying to mock up some Db data for test. I have an example how to do this with declaring mockset as variable and then using mocks. public...

How can I mock an ES6 module import using Jest?

I want to test that one of my ES6 modules calls another ES6 module in a particular way. With Jasmine this is super easy -- The application code: // myModule.js import dependency from...

How to mock RestSharp portable library in Unit Test

I would like to mockup the RestClient class for test purposes public class DataServices : IDataServices { private readonly IRestClient _restClient; public DataServices(IRestClient...

Test DriverManager.getConnection with mockito

I wrote DAO class public List<ClassRoom> getAllClassRooms() { List<ClassRoom> classRoomsList = new ArrayList<>(); String sqlStatement = "SELECT * FROM university.classrooms;"; try...

API Gateway Mock Integration Fails with 500

I have an API Gateway integration for a method/resource which works when I call it from the API but not when I actually call it: $ aws apigateway test-invoke-method --rest-api-id $REST_API_ID \ ...

How to mock functions in the same module using Jest?

What's the best way to correctly mock the following example? The problem is that after import time, foo keeps the reference to the original unmocked bar. module.js: export function bar () { ...

java.lang.IllegalStateException: Failed to load ApplicationContext error java spring-boot

Okay i went through a lot of answers but my problem is still unsolved. I am trying to test my controller - @Controller @Produces(MediaType.APPLICATION_JSON) @RequestMapping(value =...

Why Spy is not called in the Mock (Angular 4)

Can you please check the test below and see why the spy never gets called? The actual code works fine, however the test is not playing. If I spyOn something inside the this.apiSrv.fetch then test...

How to test a method dispatching custom event

I have a static method that creates a custom event and dispatches it: class MyComponent extends { static refreshComponent() { const event = new Event('refreshComponent'); ...

Cannot mock/spy class java.util.Optional

I'm trying to implement this JUnit code: private BinlistsService binlistsService = Mockito.mock(BinlistsService.class); @Mock Optional<BinLists> binList = null; @BeforeEach public void...

Jasmine/Angular: Testing the reception of a void EventEmitter onInit?

I'm writing unit testing for one of my components. Said component has a visible boolean, initialized as false. When said boolean property becomes true, the component's display css attribute goes...

AWS API Gateway and static HTML: "Execution failed due to configuration error: statusCode should be an integer which defined in request template"

I am trying to serve a static content using AWS API Gateway. When I attempt to invoke the URL, both from the test page and from curl, I get the error: "Execution failed due to configuration...

How to mock a FormBuilder for Angular Component Unit Test

I am working in an Angular 9 project. I have a component that is accepting a formBuilder as an input from a Parent Component. This is my Child component (the one I am testing): export class...

Different order of the calls to ConfigureServices between .NET Core 2.1 and 3.1 in WebApplicationFactory

During migration from .NET Core 2 to 3, I've noticed a breaking change in the WebApplicationFactory. Repro: https://github.com/lukasz-pyrzyk/orderofconfigureservices In my base library for...

Mock Static Methods in JUnit5 using PowerMockito

Need help for Mocking Static methods using JUnit5 with PowerMockito...

Cannot find a setter for ~ItemBinding~ that accepts parameter type 'androidx.lifecycle.LiveData<

Cannot find a setter for <the_derek.dogstuff.databinding.DogItemBinding app:product> that accepts parameter type 'androidx.lifecycle.LiveData<the_derek.dogstuff.db.entity.DogEntity>' If a binding...

How to mock a Jetpack Datastore in a Espresso

I switched from SharedPreferences to Jetpack DataStore. I am unable to mock the data from the datastore call in the Instrumentation test In declaration val dataStore =...

Alternatives to index.js/index.ts files? (Angular, Ionic, etc)

So, in two projects that I have worked on (one where I was brought in when the base architecture had been decided on, another in which I had some choices in the matter), I have either used or...

Jest: Cannot find module 'monaco-editor-core'

I have an reactjs(typescript) app which uses monaco-editor-core, and not monaco-editor, with custom language. Jest tests fails, if i don't mock monaco-editor-core imports, with next error: "Cannot...

mock nested properties in mockk

I have a function which uses a field in DisplayMetrics of Resources of Context class: fun getIconForDevice(context: Context, iconUrl: String): String { val metrics =...

Simple testing example of canvas element using Jest

I am trying to create a jest test for the example found in this sandbox: https://codesandbox.io/s/r3f-basic-demo-forked-297k3?file=/src/App.js Basically I would like to test the onClick...

AWS amplify, fails to compile because of mock-aws-s3

I´m trying to deploy my next.js app into aws Amplify but i keep getting the same error every time I try to deploy it. I was able to deploy the app twice already but when i tried to updated it the...