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

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
1answer
49 views

Non-testable class wrapping Java Properties with basic logic

I have written a simple java.util.Properties wrapping class. Unfortunately, in my opinion, it isn't testable at the moment and I don't have any idea how to improve ...
0
votes
2answers
51 views

Wrapper class for system dialog to allow for dependency injection

The following class is a wrapper for Microsoft.Win32.SaveFileDialog. I've implemented the usage of Microsoft.Win32.SaveFileDialog...
1
vote
2answers
38 views

PHP unit test to confirm that a validator is being called correctly

I have a Responder class whose prepare method takes an entity, checks it with a validator, and returns a response or errorResponse based on the results of validator....
10
votes
2answers
158 views

Verhoeff check digit algorithm

A recent question on credit card validation here on Code Review, led me down a dark rabbit hole of check digit algorithms. I took a stop at the Verhoeff algorithm and tried to implement it myself. ...
2
votes
1answer
72 views

Removing first or last character of a string with unit-testing

I am trying to remove a duplicate letter of first or last letter, with an exception of containing 'a' as first letter and 'l' and 'e' as last letter. However, this code does not look efficient to me ...
0
votes
2answers
41 views

Tests for Salesforce controller concerning candidates and notes

I have this controller and some test cases. Any corrections/advice are appreciated to make them better. ...
2
votes
0answers
34 views

Simple REST Base Web Server with Unit Tests

I am building out a simple web server in Go. My goal is to expand on this framework in a different application I am building. Here is my github repo https://github.com/jmacnc/gowebserver Is what I ...
28
votes
4answers
4k views

FIFO data structure in pure C

I programmed a generic queue in pure C and I'd love to receive some feedback from other programmers. You may use the following questions to guide your review. Is the API well thought and idiomatic? ...
0
votes
0answers
25 views

Writing a unit test with Jest and Vue/test-utils, using a spy or calling a function directly?

I have a switch/case function that I'm testing and I have two versions of a unit test. I do not know which is the preferred method of writing a good test. component ...
2
votes
0answers
42 views

Assigning test-data parameters by name

When creating data-driven tests with xUnit we can use the MemberDataAttribute to get the data from a member of this or other ...
5
votes
0answers
49 views

Cubic spline interpolation in Python from scratch

I implemented the cubic spline interpolation explained in https://en.wikipedia.org/wiki/Spline_interpolation as a Python class. Of course, such an interpolation should exist already in some Python ...
4
votes
0answers
35 views

Binary Heap implementation in Common Lisp and tests

I implemented a basic [binary heap] https://en.wikipedia.org/wiki/Binary_heap() in Common Lisp to learn programming using the CLOS. It is quite neat and self-contained, the core of the program is ...
1
vote
0answers
28 views

GUI Button Element with Unit Tests follow-up

This is my second attempt with unit-tests. Like my previous attempt, I would prefer a focus on the unit-tests, however I am always happy to improve my code in any way reviewers can help. Once again ...
2
votes
1answer
58 views

Minimal Haskell Unit Testing Framework

I'm trying to come up with a unit testing framework for Haskell that is small and self-contained produces TAP-compatible output exits abnormally on failure (instead of relying on the TAP consumer to ...
6
votes
2answers
65 views

GUI Button Element with Unit Tests

I would like a review on just a single class today. More important to me than a review on the class itself, however, is a review of the unit-tests I wrote for it. You see this is my first attempt at ...
4
votes
1answer
71 views

Unit testing extension method adding view location expander

Introduction I'm writing unit tests for an extension method I wrote. Its only purpose it is to wrap startup logic which extends ViewLocationExpanders list by an ...
1
vote
1answer
34 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
60 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
50 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
61 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
139 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
72 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
248 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
66 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
33 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
793 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
45 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
44 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
31 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 ...
4
votes
1answer
94 views

UpvoteJS, a simple voting widget in vanilla JavaScript

I implemented a simple voting widget like the one used on Stack Exchange sites, to use for other purposes (see live on bashoneliners.com), as a reusable package, dubbed UpvoteJS. Here's how it works: ...
2
votes
1answer
332 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 ...
1
vote
1answer
116 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
55 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 ...
1
vote
2answers
60 views

Two BDD unit tests for an account repository with identical code

I am testing my repository class: interface AccountRepository{ void save(Account account); Optional<Account> findById(Long id); } And when writing ...
7
votes
0answers
119 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
101 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
61 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
73 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
77 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
154 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
115 views

Simple stringifying using << operator

Background I wrote my_length class and some code. my_length can be stringified using ...
4
votes
1answer
140 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
44 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
77 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
90 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
47 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
92 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
33 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 ...