When should I mock?

Mock objects are useful when you want to test interactions between a class under test and a particular interface. For example, we want to test that method sendInvitations(MailServer mailServer) calls MailServer.createMessage() exactly once, and also calls MailServer.sendMessage(m) exactly once, and no other methods are called on the MailServer interface. This is when we can use … Read more

Mock functions in Go

Personally, I don’t use gomock (or any mocking framework for that matter; mocking in Go is very easy without it). I would either pass a dependency to the downloader() function as a parameter, or I would make downloader() a method on a type, and the type can hold the get_page dependency: Method 1: Pass get_page() … Read more

How to mock imported named function in Jest when module is unmocked

Use jest.requireActual() inside jest.mock() jest.requireActual(moduleName) Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. Example I prefer this concise usage where you require and spread within the returned object: // myModule.test.js import { otherFn } from ‘./myModule.js’ jest.mock(‘./myModule.js’, () => ({ …(jest.requireActual(‘./myModule.js’)), … Read more

Configuring IntelliJ IDEA for unit testing with JUnit

If you already have a test class, but missing the JUnit library dependency, please refer to Configuring Libraries for Unit Testing documentation section. Pressing Alt+Enter on the red code should give you an intention action to add the missing jar. However, IDEA offers much more. If you don’t have a test class yet and want … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)