unit-testing

How to mock external dependencies for final objects?

走远了吗. 提交于 2021-01-28 12:31:43
问题 public class A{ private final B b; public void meth() { //Some code Integer a = b.some_method(a,fun(b)); //Some code } private fun(int b) { return b; } } when(b.some_method(anyInt(),anyInt())).thenReturn(100) How to mock the externally dependency when writing unit tests for class A. When i mock dependency in the above way, the value of "a" is not getting assigned to 100 as expected. 回答1: Actually the answer of Jakub is correct. Maybe you need an example to understand how to do it. Check the

Jest test fails for async function that calls another async function

守給你的承諾、 提交于 2021-01-28 12:10:25
问题 I am trying to test an async function that uses data returned by another async function. Here is the code to explain my problem: StudentInfo.js export async function getData() { //studentData imported from another file return new Promise(resolve => { setTimeout(() => { resolve(studentData); }, 5000); }); } export async function filterStudents() { const studentData = await StudentInfo.getData(); //computations return filteredData; //object } StudentInfo.test.js import * as studentInfo from

C# out of scope objects not getting collected

余生颓废 提交于 2021-01-28 11:45:47
问题 I'm trying to build my first unit tests and have a class that increments and decrements an instance counter in it's constructor and destructor respectively. I have a test to make sure this works but it fails, it seems that other instances of the class from my other tests aren't having their destructor called when they go out of scope. public class Customer { public Customer() { ++InstanceCount; } public Customer(int customerId) { CustomerId = customerId; ++InstanceCount; } ~Customer() { -

Error while testing flask application with unittest

社会主义新天地 提交于 2021-01-28 11:44:00
问题 I have ModuleNotFoundError: No module named 'project' while trying to run test_req.py My project structure is: ├── instance/ │ ├── flask.cfg ├── project/ │ ├── __init__.py │ ├── base_processing.py │ ├── models.py | ├── views.py │ ├── templates/ │ │ ├── base.html │ │ ├── login.html │ │ ├── note.html │ │ ├── notes.html │ └── static/ │ │ │ └── tests/ │ ├── test_req.html ├── run.py My UnitTest file is: # project/test_req.py import unittest import os from project import app from project.models

SpecFlow equivalent to parameterized test fixture

别来无恙 提交于 2021-01-28 10:34:04
问题 I’m using SpecFlow to write a set of tests, and I’d like to run each test multiple times, with different input data. I could do this with scenario outlines, but I want to run every scenario in the feature file with the same test cases. I know I can use the Background to share the setup for one case, but I’m looking for something like a cross between Background and Scenario Outline, where I can supply a table of data to the Background and run the entire feature file once per row. In NUnit, I’d

SpecFlow equivalent to parameterized test fixture

陌路散爱 提交于 2021-01-28 10:32:09
问题 I’m using SpecFlow to write a set of tests, and I’d like to run each test multiple times, with different input data. I could do this with scenario outlines, but I want to run every scenario in the feature file with the same test cases. I know I can use the Background to share the setup for one case, but I’m looking for something like a cross between Background and Scenario Outline, where I can supply a table of data to the Background and run the entire feature file once per row. In NUnit, I’d

SpecFlow equivalent to parameterized test fixture

荒凉一梦 提交于 2021-01-28 10:22:26
问题 I’m using SpecFlow to write a set of tests, and I’d like to run each test multiple times, with different input data. I could do this with scenario outlines, but I want to run every scenario in the feature file with the same test cases. I know I can use the Background to share the setup for one case, but I’m looking for something like a cross between Background and Scenario Outline, where I can supply a table of data to the Background and run the entire feature file once per row. In NUnit, I’d

SpecFlow equivalent to parameterized test fixture

断了今生、忘了曾经 提交于 2021-01-28 10:21:47
问题 I’m using SpecFlow to write a set of tests, and I’d like to run each test multiple times, with different input data. I could do this with scenario outlines, but I want to run every scenario in the feature file with the same test cases. I know I can use the Background to share the setup for one case, but I’m looking for something like a cross between Background and Scenario Outline, where I can supply a table of data to the Background and run the entire feature file once per row. In NUnit, I’d

SpecFlow equivalent to parameterized test fixture

纵然是瞬间 提交于 2021-01-28 10:21:29
问题 I’m using SpecFlow to write a set of tests, and I’d like to run each test multiple times, with different input data. I could do this with scenario outlines, but I want to run every scenario in the feature file with the same test cases. I know I can use the Background to share the setup for one case, but I’m looking for something like a cross between Background and Scenario Outline, where I can supply a table of data to the Background and run the entire feature file once per row. In NUnit, I’d

SpecFlow equivalent to parameterized test fixture

点点圈 提交于 2021-01-28 10:20:42
问题 I’m using SpecFlow to write a set of tests, and I’d like to run each test multiple times, with different input data. I could do this with scenario outlines, but I want to run every scenario in the feature file with the same test cases. I know I can use the Background to share the setup for one case, but I’m looking for something like a cross between Background and Scenario Outline, where I can supply a table of data to the Background and run the entire feature file once per row. In NUnit, I’d