Latest Questions tagged Unit Testing

Browse all latest questions tagged Unit Testing

40
Votes
Published 16 Sep, 2022
Java - Unit testing equals and hashcode - a complexity story

I'm having a moral dilemma. I have some value objects in my application, which are immutable and extremely simple. I've generated the equals and hashcode with an IDE (intellij in my case) but doing th...

96
Votes
Published 21 Aug, 2022
Python - Python: Unit Test to check if objects are same at different location?

easiest way to explain this one: import unittest from element import Element class TestHTMLGen(unittest.TestCase): def test_Element(self): page = Element("html", el_id=False) se...

55
Votes
Published 23 Aug, 2022
Python - Proper way to test Django signals

I'm trying to test sent signal and it's providing_args. Signal triggered inside contact_question_create view just after form submission. My TestCase is something like: def test_form_should_post_...

53
Votes
Published 01 May, 2022
Python - Unittest.mock: asserting partial match for method argument

Rubyist writing Python here. I've got some code that looks kinda like this: result = database.Query('complicated sql with an id: %s' % id) database.Query is mocked out, and I want to test that the...

22
Votes
Published 04 Jul, 2022
Reactjs - React Testing Library with TypeScript: Set an input's value

I'm building a React application using TypeScript. I do my component tests using React Testing Library. Let's say you have simple form like this: import React from 'react' function Login({onSubmit}...

7
Votes
Published 19 Apr, 2022
React - ReactTestUtils has been moved

I'm starting learning React and while I was doing some tests i noticed two warning messages: Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning....

6
Votes
Published 24 Apr, 2022
Python - Run all tests from subdirectories in Python

I am at my wits end with trying to get all my unittest to run in Python. I have searched about 30 different posts and the unit test documentation but still cannot figure it out. First I have two test...

160
Votes
Published 15 Sep, 2022
Java - Run single test from a JUnit class using command-line

I am trying to find an approach that will allow me to run a single test from a JUnit class using only command-line and java. I can run the whole set of tests from the class using the following: java...

24
Votes
Published 26 Apr, 2022
Python - Why python mock patch doesn't work?

I have two files spike.py class T1(object): def foo(self, afd): return "foo" def get_foo(self): return self.foo(1) def bar(): return "bar" test_spike.py: from unitt...

106
Votes
Published 24 Apr, 2022
Javascript - How to test chrome extensions?

Is there a good way to do this? I'm writing an extension that interacts with a website as a content script and saves data using localstorage. Are there any tools, frameworks, etc. that I can use to te...

273
Votes
Published 06 May, 2022
Python - How do I run all Python unit tests in a directory?

I have a directory that contains my Python unit tests. Each unit test module is of the form test_*.py. I am attempting to make a file called all_test.py that will, you guessed it, run all files in the...

17
Votes
Published 02 Oct, 2022
Java - Mockito: multiple calls to mocked UriBuilder keep appending to original URI

I am currently writing some unit tests for legacy code in a rest api application. One particular api call generates a list of URIs using the UriInfo api from Jax-RS. When I mock this interface, I am a...

25
Votes
Published 06 Sep, 2022
Java - How to mock a autowired list of Spring beans?

I've read plenty of articles about how to mock Spring's bean and their autowired fields. But there is nothing I could find about autowired lists of beans. Concrete problem I've a class called FormVa...

13
Votes
Published 17 Aug, 2022
Python - "ModuleNotFoundError: No module named ..." when trying to make unit tests in Python

Problem I am trying to make unit tests for my project, but I am having issues figuring out where my error is in regards to absolute importing the module to test. I am using Visual Studio Code as my ID...

37
Votes
Published 08 Jul, 2022
Reactjs - Jest/Enzyme test not giving expected output?

I have a simple react component I am trying to test with enzyme. To me the test seems trivial and should pass (simply checking the existence of a div) : import React, {Component} from 'react'; import...