Shouldn’t NSUserDefault be clean slate for unit tests?

Using named suites like in this answer worked well for me. Removing the user defaults used for testing could also be done in func tearDown(). class MyTest : XCTestCase { var userDefaults: UserDefaults? let userDefaultsSuiteName = “TestDefaults” override func setUp() { super.setUp() UserDefaults().removePersistentDomain(forName: userDefaultsSuiteName) userDefaults = UserDefaults(suiteName: userDefaultsSuiteName) } }

Mock final class with Mockito 2

Weird that your solution seems to work. According to their documentation on Github it says. Mocking of final classes and methods is an incubating, opt-in feature. It uses a combination of Java agent instrumentation and subclassing in order to enable mockability of these types. As this works differently to our current mechanism and this one …

Read more

NestJS – Test suite failed to run Cannot find module ‘src/article/article.entity’ from ‘comment/comment.entity.ts’

You can tell Jest how to resolve module paths by configuring the moduleNameMapper option, which is useful if you’re using packages like module-alias or if you’re using absolute paths. Add these lines to your Jest configuration: { // … “jest”: { // … “moduleNameMapper”: { “^src/(.*)$”: “<rootDir>/$1” } } } Now modules that start with …

Read more

unit test mocha Visual Studio Code describe is not defined

Finally!!! After a long search and reading some tutorials and comments I found the solution: the problem was with the config. Open the test config file and delete the following lines: “-u”, <<<< delete this line “tdd”, <<<< delete this line launch.js “version”: “0.2.0”, “configurations”: [ { “type”: “node”, “request”: “launch”, “name”: “Mocha Tests”, “program”: …

Read more

Difference between Microsoft.VisualStudio.TestPlatform.TestFramework and Microsoft.VisualStudio.QualityTools.UnitTestFramework

MSTest has been released as a new NuGet package solution that is no longer tightly coupled to the Visual Studio version. Your new projects are using MSTest 2.0. MSTest V2 release annoucement: https://devblogs.microsoft.com/devops/taking-the-mstest-framework-forward-with-mstest-v2/

How to call setup once for all tests and teardown after all are finished

The OP’s requirement was for setup and teardown each to execute only once, not one time per module. This can be accomplished with a combination of a conftest.py file, @pytest.fixture(scope=”session”) and passing the fixture name to each test function. These are described in the Pytest fixtures documentation Here’s an example: conftest.py import pytest @pytest.fixture(scope=”session”) def …

Read more