All Questions
418
questions
-1
votes
1
answer
30
views
XCode tests issue: 'any Protocol' does not conform to expected type 'Protocol' insert 'as! Protocol'
Started adding tests to supplementary objects
Tested class code:
class TokenAdapter {
private let tokenProvider: TokenProviderProtocol!
private let session: SessionProtocol!
// MARK: - Init
...
0
votes
1
answer
41
views
MockMvc test always returns 200 regardless of JWT authorities
@Test
public void testGetOrders() throws Exception {
mockMvc.perform(get("/admin/api/orders/")
.with(jwt().authorities(new SimpleGrantedAuthority("...
0
votes
1
answer
46
views
Mock patching an endpoint unittest that makes several requests to third party
I have a single endpoint written using django ninja. This endpoint executes a crawler that performs several requests. The sequence of requests has 3 different routines depending on whether or not the ...
0
votes
0
answers
42
views
Python unittest how to mock function which external function is defined in __init__.py
I would like to test my_func2 that is calling my_func1. I would like to mock my_func1, but I don't know how can I do it when my_func2 is imported in my_package.__init__.py. When I delete that import, ...
1
vote
0
answers
37
views
Best Practice for Using Fake Objects in Multi-Module Projects for Testing
I recently came across a blog post (https://testing.googleblog.com/) discussing the use of fake objects over mocking for testing purposes. The post detailed creating fake objects for necessary ...
0
votes
1
answer
124
views
How to mock classes with factory methods in Substitute? (for using ForPartsOf to keep default behaviour while still checking received calls)
I want to mock a Logger using NSubstitute. But instead of using Substitute.For, I want to use Substitute.ForPartsOf to:
both call the real implementation (to continue logging to the console)
and ...
1
vote
0
answers
66
views
Injection of mocked service fails for nested service when testing an Angular app with ng-mocks
We started using the very nice ng-mocks for our test, but I have trouble getting the mock injection right for this case:
OurService that uses the DatetimeService and NumberFormatterService.
...
0
votes
0
answers
65
views
Mocking constructors in main func
I would like to find a better way to mock my constructor. The constructor itself already returns an interface, thanks to which I can mock its functions in tests.
//main.go
var createSSMClient = ssm....
0
votes
1
answer
91
views
Test a function called in else condition
I have written a code where I am calling a function in the else case which returns a string. I have mocked it and asserted it to be called once. But this is failing for some reason. This decreases my ...
2
votes
1
answer
491
views
Capture multiple arguments with NSubstitute
I am using NSubstitute to write a unit test, and am trying to capture multiple method arguments passed in a method call.
I understand that I can capture a single argument using the Arg.Do<T>() ...
1
vote
1
answer
77
views
Why is my phyton mock only working with a specific way of import?
I have a utils class that besides other stuff has a function to get an id:
# utils.py
def get_id():
return ...
Also, there is another class, lets say its about cars, that uses this function:
# ...
1
vote
1
answer
32
views
Does Mockery clone __get method? [duplicate]
I am using Laravel 9 together with mockery/mockery version 1.6.6
I have some strange behavior when I mock an Eloquent model.
The eloquent Model has a __get() method defined as :
public function ...
0
votes
2
answers
42
views
How do I mock a function called inside the function that I am testing?
My file structure is like this:
pytests/
├── moduleA/
│ ├── functions/
│ │ └── process_moduleA.py
│ └── test_process_moduleA.py
└── utils/
└── archive.py
in process_moduleA, I have ...
0
votes
0
answers
41
views
How to intercept/mock a function called by an eventListener
I am learning about unit testing and I have been implementing it into my current project with success somewhat, using vitest.
But I don't really know how to tackle this situation, let's say that I ...
0
votes
2
answers
47
views
How to test that the method of an instance has been called?
Let's say I have the following piece of code:
class MyClass:
def __init__(self, value=1):
self.value = value
self.destructive_stuff()
def destructive_stuff(self):
...