Stack Exchange Network

Stack Exchange network consists of 174 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

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.

2
votes
0answers
17 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
23 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 ...
-1
votes
0answers
32 views

is there a better way to test this class? [on hold]

Recently, I am learning unit test and try to use this skill in my project. However, I have some question about how to test following code. ...
2
votes
1answer
36 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 ...
-2
votes
0answers
38 views

Proper setup for testing a controller

I have the following testing suite that I'd like to get criticized and suggested improvements to and weaknesses in. The test is carried out on a simple controller that returns a full list of entities ...
0
votes
0answers
12 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
29 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
28 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
41 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
98 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
78 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
49 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
60 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
74 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
135 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
85 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
33 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
56 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
73 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
38 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
71 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
29 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
51 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
31 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
51 views

Unit Testing for Spring Controller

This is my first attempt to do unit test for one of my controllers. ...
4
votes
3answers
62 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
50 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
30 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
124 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
48 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
124 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
60 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
113 views

Retry Class in Java

I have the following Java code used to retry a certain actions/methods ...
1
vote
0answers
48 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
858 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 ...
10
votes
1answer
154 views

BattleShip Grid: Classes and Tests

In my ongoing quest to demonstrate how VBA code can absolutely be object-oriented, I've started implementing a game of Battleship in pure VBA. This is a rather large project, so I'll split the ...
1
vote
0answers
69 views

Unit test for class converting between DTOs and entities

Is this correctly written test? Tested class is responsible for converting from dto to entity class and i wanted to test it. Are these tests useful and well designed? I have a problem understanding ...
3
votes
1answer
108 views

Pytest fixture for testing a vertex-parsing function

I have just started using pytest and I am still getting used to how they do things. It seems like fixtures are at the core of the library, and that they can be used for making small pieces of dummy ...
1
vote
1answer
51 views

Mocha + chai tests

I have been making an effort to add a fair amount of unit testing into my code. However, I find myself going against the DRY principle quite a bit. I am currently running tests on my API with my ...
5
votes
2answers
66 views

LinkedList class implementation in Python

I was solving this problem for implementing LinkedList and ListNode classes, and Insert and <...
5
votes
2answers
770 views

Remove the first value for a doubly linked list

You need to remove the first element which contains a given value from a doubly linked list. I created two solutions since I find the edge case of removing the first element to be problematic. So I ...
2
votes
1answer
79 views

Testing higher order reducer with jest

I'm trying to understand conception of creating unit tests for the frontend applications. I have created higher order reducer: ...
3
votes
2answers
196 views

Merge two sorted lists in Python

Merge two sorted lists ...
2
votes
1answer
82 views

Unit tests for os.scandir/scantree a directory

I wrote my first series of test for this simple function: ...
3
votes
1answer
173 views

Autocomplete implementation in Python

I have an autocomplete implementation in Python, and it passed all of the unit tests that I have included at the bottom. ...