unit-testing

How to override a method in unit tests that is called from which the class being tested

百般思念 提交于 2021-02-16 18:33:06
问题 I am testing a class A's function func1. Func1 has a local variable of Class B and calls B's function func2. Code looks something like this: public Class A { public func1() { B object = new B(); int x = object.func2(something); } } When I am testing func1 in its unit tests, I don't want func2 to get called. So I am trying to do something like this in the test: B textObject = new B() { @override int func2(something) { return 5; } } But it is still calling the func2 in the class B. Please

Trying to Test a Controller with a UrlHelper

▼魔方 西西 提交于 2021-02-16 18:07:17
问题 Trying to create a URLHelper for testing purposes throws a NullReferenceException . Example: [Fact] public async void AuthenticateAsyncTest() { // Arrange var controller = new Controller(serviceProvider) { Url = new UrlHelper(new ActionContext()) // Exception thrown }; // Act var result = await controller.Authenticate() as ViewResult; // Assert Assert.NotNull(result); } Every time I run this Test, the Exception that is thrown in Url = new UrlHelper(new ActionContext()) is: Exception.Message:

Mocked unit test raises a “stop called on unstarted patcher” error

谁说胖子不能爱 提交于 2021-02-16 14:45:38
问题 When running the test bellow, I got a stop called on unstarted patcher . def test_get_subvention_internal_no_triggered_admission(self): billing_cluster = BillingClusterFactory() subvention = SubventionFactory(billing_cluster=billing_cluster) convive_sub = ConviveFactory(subvention=subvention, billing_cluster=billing_cluster) order_5 = OrderFactory(beneficiary=convive_sub) order_operation_5 = CreationOrderOperationFactory(order=order_5) with patch('orders.models.Order.subvention_triggered_same

Unit tests panic when returning dereferenced struct attribute rather than struct

偶尔善良 提交于 2021-02-11 18:24:40
问题 How does one go about testing a function that is returning a struct attribute that is of type string or number, rather than the struct itself? I am trying to test the Lambda Code block with the Test Code block. In Lambda Code block below, I am returning *resp.UserPoolClient.ClientSecret which dereferences to a string , rather than the *string . When I run my test, I believe I get a panic error as *resp.UserPoolClient.ClientSecret is nil in the debugger. Is my returning of the de-referenced

How do I configure my CMake project to run all unit tests?

六眼飞鱼酱① 提交于 2021-02-11 17:49:17
问题 I have a C++ project using cmake as the build tool. My directory structure looks like the following. . ├── cmake-build-debug ├── include ├── src └── tests When I am inside cmake-build-debug , I run cmake .. followed by make clean && make && make test . What I noticed is that only the first unit test is run. How do I configure my project so that when I run make test , all unit tests are run? At the root, my CMakeLists.txt looks like the following. cmake_minimum_required(VERSION 3.10) project

ResourceWarning for a file that is unclosed but UnitTest is throwing it

大憨熊 提交于 2021-02-11 15:39:15
问题 I have a function like this: def init_cars(self, directory=''): #some_code cars = set([line.rstrip('\n') for line in open(directory + "../myfolder/all_cars.txt")]) #some_more_code I am writing unittest and when I run them, I get the following error: ResourceWarning: unclosed file <_io.TextIOWrapper name='../myfolder/all_cars.txt' mode='r' encoding='UTF-8'> names = set([line.rstrip('\n') for line in open(directory + "../myfolder/all_cars.txt")]) ResourceWarning: Enable tracemalloc to get the

How to Mock config file in .Net Core with xUnit

跟風遠走 提交于 2021-02-11 15:00:44
问题 I want to mock the config file values in .NET Core. I am using xUnit for unit test. I am using application insight. I use config file for configuration. Now I want to mock that .cs config file in my unit test case. var configurationPackage = statelessServiceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config"); var appInsightsSection = configurationPackage.Settings.Sections["AppInsightsConfig"]; var appInsightsInstrumentationKey = appInsightsSection.Parameters[

How to Mock config file in .Net Core with xUnit

≡放荡痞女 提交于 2021-02-11 15:00:03
问题 I want to mock the config file values in .NET Core. I am using xUnit for unit test. I am using application insight. I use config file for configuration. Now I want to mock that .cs config file in my unit test case. var configurationPackage = statelessServiceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config"); var appInsightsSection = configurationPackage.Settings.Sections["AppInsightsConfig"]; var appInsightsInstrumentationKey = appInsightsSection.Parameters[

Why does the ordering of it functions matter in this jest test?

拟墨画扇 提交于 2021-02-11 14:52:27
问题 I have the following component... export default class TextInput extends PureComponent<TextInputProps> { private handleOnChange = (event: OnChangeEvent): void => { if (!this.props.disabled && this.props.onChange) { this.props.onChange(event) } } private handleOnBlur = (event: OnBlurEvent): void => { if (!this.props.disabled && this.props.onBlur) { this.props.onBlur(event) } } public render(): ReactNode { return ( <Styled.TextInput id={this.props.id} type={this.props.type} onChange={this

Why does the ordering of it functions matter in this jest test?

只谈情不闲聊 提交于 2021-02-11 14:50:20
问题 I have the following component... export default class TextInput extends PureComponent<TextInputProps> { private handleOnChange = (event: OnChangeEvent): void => { if (!this.props.disabled && this.props.onChange) { this.props.onChange(event) } } private handleOnBlur = (event: OnBlurEvent): void => { if (!this.props.disabled && this.props.onBlur) { this.props.onBlur(event) } } public render(): ReactNode { return ( <Styled.TextInput id={this.props.id} type={this.props.type} onChange={this