Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [unit-testing]

Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

1
vote
0answers
19 views

Unit Test case to check if localstorage is empty once I logout of the Web app

I am trying to clear my localstorage when I am logging out of the application. I want to write a unit test case in Jasmine to check if this task is performed when logout function is run. I am writing ...
1
vote
1answer
54 views

Abstracting getter and setter method references for testing

Is the following code easy to understand? If not how should it be changed to be more understandable. The purpose of this is reducing similar code in unit tests. This avoids repeating lines for calling ...
1
vote
0answers
46 views

Linked list implementation along with unit test - Round 3

Here are the changes I've made thanks to suggestions made by @vnp, and @Henrik Hansen. Here is the link to the previous code review: Linked list implementation along with unit test - Round 2 I've ...
3
votes
2answers
59 views

Linked list implementation along with unit test - Round 2

Here is the link to the next round of code review: Linked list implementation along with unit test [Round 3] Here's the link to the previous code review: Linked list implementation along with unit ...
7
votes
1answer
118 views

Linked list implementation along with unit test

I've already made all the changes suggested here. Here is the link for round 2: Linked list implementation along with unit test [Round 2] I want to see how other people think of my code, so here it ...
7
votes
0answers
64 views

TDD tests for every view and its permissions in a REST API

I am currently developing a Django Rest Framework API with TDD. I have 15 tests and counting for two views, which doesn't seem right to me. It takes me a lot of time to write the tests and a lot of ...
4
votes
4answers
232 views

Poker Game: Unit testing different poker hands without violating DRY principles

I'm currently in the process of refactoring an old poker game which violates many of the SOLID principles. I was trying to use the TDD approach to refactoring and I found myself having to hard code ...
2
votes
1answer
52 views

Android Java Unit Testing model class

I'm trying to get familiar with unit testing. I never implement TDD previously, but I believe it's the best way to write software. So, here I'm trying to test my ...
0
votes
0answers
29 views

threaded event loop “interrupt” unit test without deadlocks

I have an event_loop implementation (basically an event/command queue and an exec function). I have added ...
4
votes
2answers
752 views

Fake utcnow for the pytest

I want to create a pytest with a fake utcnow, but also I need to preserve the functionality of all other datetime methods. ...
1
vote
0answers
32 views

Testing a Controller in a while loop

I would like to see suggestions if my code could be more improved. In my controller I have a line: self.bool_value = False # for testing which in my opinion ...
3
votes
0answers
39 views

Paginator module in Elixir

I wrote this Paginator module that's part of a small application that displays Elixir Github repos in a table. I'm new to Elixir and looking for code improvements with as much as possible. Best ...
2
votes
0answers
37 views

setting up mock and fixtures for for multiple pytest unit tests

I've been implementing a MySQL client with the later purpose of automating monthly reports. At the moment, I've got two distinct use cases: Executing a query and printing the results in files. The ...
1
vote
0answers
26 views

Python script to add unittest decorators to source code files

This is a simple Python script to add @unittest.skipUnless() decorators in a specified format above every function starting with ...
2
votes
1answer
94 views

Unit test for a function that transforms a PANDAS dataframe

I am currently working on a project that uses many dataframe wrangling. The intention is to write test to check that the output functions are correct. I have written a test for a dataframe function ...
0
votes
0answers
37 views

Unit testing static method that imports environment file

I'm (very) new to writing unit tests and I'm wondering how I should approach testing a static method that constructs our API endpoints based on what the properties are set to in our ...
1
vote
1answer
40 views

Simple unit test in C of input using freopen

Here is an initial attempt at unit test of user input in C. The thing that feels unusual is the use of freopen to send the test data to stdin. Are there better ways to implement this kind of test? <...
1
vote
0answers
30 views

Testing class which returns big dictionary

I have simple class with the public build method I want to test. Currently I assert all values it returns in every test. Is it a good practice or I should write one ...
0
votes
1answer
44 views

Trying to follow BDD in tests, end up with two exactly same tests

I am testing my repository class: interface AccountRepository{ void save(Account account); Optional<Account> findById(Long id); } And when writing ...
7
votes
0answers
112 views

Building Slack message

I have the function which builds and return Slack message with text and attachments. How can I refactor this function to make it ...
4
votes
1answer
87 views

Tic tac toe with unbeatable AI

I wrote this simple command line interface tic tac toe game with unbeatable AI with unittests. Looking for any suggestions how to improve it. Game: ...
6
votes
1answer
58 views

Unit testing for Splay Tree in Python

I am creating a test class for the following code. splay_test.py which is the unit test code for splay tree. I needed help with writing unit tests for python to get %100 coverage. I am very bad at ...
1
vote
1answer
65 views

Quicksort in C with unit testing framework

This is my quicksort There are many like it but This quicksort is mine. So, quicksort, in C, with a big framework to test it six ways from Sunday. Passed the tests nicely, but there may be warts, or ...
2
votes
1answer
75 views

This technique for functional programming, and testing functional programming

I've been playing around with functional programming and testing with jest recently. An issue I've run into, is that it's hard to mock ES6 module exports directly. See this Stack Overflow question ...
6
votes
2answers
142 views

Sorting algorithms with Python project

I wrote my first project in Python and I would like to know if this is correct. I prepared some guidelines I want to ask. (I know that I don't have any documentation yet). In the future I want to ...
3
votes
1answer
114 views

Simple stringifying using << operator

Background I wrote my_length class and some code. my_length can be stringified using ...
4
votes
1answer
109 views

Bubble sort algorithms and unittest in Python

I am quite new in Python and I am starting my journey with sorting algorithms, PEP8 and the Zen of Python. So far i wrote a post BubbleSort and I drew conclusions and followed the advices. I ...
1
vote
0answers
39 views

TDD for Ruby On Rails API for group event items

I found myself working in this coding exercise for a work offer. I tried to apply TDD in the process but I didn't get any feedback from the company and I really would like to know what can be improved ...
1
vote
1answer
63 views

Prepare a cross-platform QT C-wrapper class for unit testing and mocking

The situation I recently started a cross platform QT project (arm, linux-x86, windows) that aims to interact with CAN-Bus hardware. I want to learn and get used to unit testing from scratch as good ...
2
votes
1answer
82 views

Calculate arithmetic expression represented by a string, in Java

I saw that interview question online and gave it a try: Implement a function that gets a string which represents an arithmethic expression: contains only numbers or the the operators: '+', '-', '*', '/...
1
vote
1answer
44 views

Testing a service that makes database calls, without a database

I'm working on a new service, for the past year I haven't needed to write tests from scratch. I've either been bug fixing, or adding features that require modification of tests, but not writing ...
5
votes
1answer
84 views

Using Python decorators to do Hoare Logic

I'm relatively new to Python from a strong Java background. I am trying to create a base class to do Hoare Logic. Function decorators seem to be the way to go with this. I've produced the following ...
2
votes
1answer
30 views

Testing a probabilistic prime-testing algorithm that may fail

I have implemented Pollard's Rho algorithm in Java. Due to the nature of it there is a small chance for it to fail (have not seen it happening yet). Since I do not ...
1
vote
1answer
54 views

Two approaches to Logging when Unit Testing with Python

Python allows logging to be used in several ways. What are the relative merits of these two approaches to Logging when Unit Testing with Python? Is one approach superior or does each approach suit ...
3
votes
1answer
33 views

Two different styles of testing a custom JSON schema generator

I'm a junior programmer, and I've only been in the industry a couple of months. One of the aspects that I struggle with most is testing my code. I can write tests, and I can ensure that my code ...
3
votes
1answer
54 views

Unit Testing for Spring Controller

This is my first attempt to do unit test for one of my controllers. ...
4
votes
3answers
67 views

Print the first, last, and in-between integers of a range

Given our spec from Code Golf: Given two integers, output the two integers, and then the range between them. The order of the range must be the same as the input. Examples: ...
5
votes
1answer
56 views

Unit testing for Python function that checks whether a value is in a range

This is the first time I've ever tried to write unit tests before, so I wanted to post here to see if I'm doing it "right". I read a couple of articles on the subject, but I work alone so I want to ...
2
votes
1answer
51 views

Unit tests for directory-entry counter

I have a function that simply counts the number of files in a directory. To test this function I am using temporary files which are great in the respect that they are deleted upon creating. However, ...
1
vote
1answer
26 views

Test-Spy Implementation

I have tried to write a test-spy myself. Just for getting more familar with the topic. Here's the code: ...
3
votes
0answers
39 views

Jest unit test that handles a wrapped Promise

I've wrapped an imported function (a promise) and attempted to write unit tests that bring my codebase to 100% coverage. ...
3
votes
2answers
182 views

Unit testing a generic interface: proposal to avoid test duplication for different generic types

I'm looking for feedback on a way to avoid massive code duplication on unit tests of a generic interface. It is expected that the interface will have several dozen implementations with common ...
0
votes
1answer
66 views

Assert LinkedHashMap element in jUnit test [closed]

So I have some test, maybe the given side of that test is not so important to catch the point of my confusion. I wrote ...
2
votes
3answers
126 views

Exercise to refactor a class with various credit limit rules

I recently did a programming exercise for a company which I didn't pass. I didn't get any good feedback from my test so I wanted some advice/opinions for what I did wrong and what I could have done ...
1
vote
0answers
14 views

Proper design for testing silently passed errors

I am writing a function to raise an error if a csv/tsv file does not use valid separators. However, due to existing code, currently I am handling all other exceptions to be handled silently. (There ...
3
votes
0answers
73 views

Unit testing a custom collection

To enable unit testing in the VBA IDE I'm using https://github.com/rubberduck-vba/Rubberduck. I've created a class and a custom collection class to work with structural members I need to filter. The ...
1
vote
2answers
46 views

Writing unit tests for exception should be thrown case

Can anyone here comment on the quality of this test case? I am here testing for the exception should be thrown scenario. I mean it works but is it the correct way to unit test for the scenarios where ...
2
votes
1answer
135 views

Retry Class in Java

I have the following Java code used to retry a certain actions/methods ...
1
vote
0answers
55 views

Insert Emojis Into Outlook Email With VBA Application (For those of us who cant use add-ins)

I cannot use add ins here so I set out to create an excel application that could get the job done. I suppose that I could easily transport this into outlook? Basically I want to click one of the ...
7
votes
3answers
936 views

Program to see how many points lie strictly inside a convex polygon

The program takes in a set of coordinates that defines the polygon. It then takes in a set of points. The idea is to find out how many of these points lie strictly inside the convex polygon (not on ...