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.
979
questions
1
vote
0answers
18 views
Testing a javascript function that performs side effects
Application context
I am working on a game I call "Apes and Snakes". So far the code only allows players to connect to a host using a room code and WebRTC. Players and the host send messages ...
2
votes
1answer
42 views
Replace words from a file with words from a dictionary based file
I'm working on a coding challenge that tasks me with taking a file with a dictionary, reading from it, and then replacing the matching words from the input file with what is found in the dictionary.
I ...
-2
votes
1answer
63 views
Testing Code That Has Time Delays [closed]
Whilst refactoring an app I'm working on I moved a piece of code from the business logic layer to a helper. The code in question is a fire and forget method that will execute a piece of code if it ...
1
vote
0answers
36 views
Using pytest fixtures for the expected answers to a test?
I want to test a number of different functions I have written to solve the Fizzbuzz challenge and would like to know what is the best way to check the result?
Each function returns a list of the ...
4
votes
2answers
135 views
Are these Unit tests OK or am I implementing an antipattern or not following best practices
I am testing a Spring boot service using JUnit 5 and Mockito. I haven't spent much time on unit testing in the past so I'm not sure if I'm accidentally implementing an anti-pattern or not following ...
1
vote
0answers
28 views
Rainfall challenge: procedural implementation
This evening I have seen the text of the Rainfall Challenge posted seven years ago by Hunter McMillen. I did not look at his solution (besides, I have no clue about perl), but I was intrigued by the ...
2
votes
1answer
34 views
Portable Build System for Virtual Machine with Editor and Unit Tests
I am automating the building and unit testing of a personal
project using shell scripts
, CMake and make on the latest version of Fedora Linux. I have also tested building on the latest version of ...
2
votes
0answers
29 views
Unit Test template function with terminal input
I wrote some template function, which helps me with reading input from terminal, doing error handling, validating input.
The full code with template specialisation for strings looks like this:
...
1
vote
1answer
67 views
What to test on a rest API?
I created a rest controller with Spring Boot, I am trying to learn what I should write on my tests, right now I only check status codes and keys existence. I am planning to build an API to showcase at ...
0
votes
1answer
85 views
Is this enough for unit testing a basic controller?
My pet project, is a community driven lyrics archive, it is still a work in progress, and all code is open sourced on GitHub.
I have a local git branch ...
1
vote
1answer
19 views
Testing Remedy-on-Demand REST API code
I am writing a python module to interact to the ROD (remedy on demand) BMC ticketing product. So far I have only written the log in and log out methods and tests. Before I crack on with the more ...
6
votes
1answer
63 views
Writing unit testing for conference management class
I try to use unittest for conference class, but I am not sure that I have considered all condition or more complex tests should be added?
conference.py
...
0
votes
0answers
67 views
Various Type Test Cases for recursive_transform Template Function in C++
This is a follow-up question for Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++, A recursive_transform Template Function Implementation with ...
6
votes
1answer
128 views
A Various Container Type Arbitrary Nested Iterable Generator Function Implementation in C++
This is a follow-up question for std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++ and std::deque and std::list Type Arbitrary Nested Iterable ...
7
votes
1answer
119 views
Non-nested std::deque and std::list Generator Function for arithmetic_mean Function Testing in C++
This is a follow-up question for A non-nested test_vectors_generator Function for arithmetic_mean Function Testing in C++ and An arithmetic_mean Function For Various Type Arbitrary Nested Iterable ...
8
votes
1answer
135 views
Generic test case templates
I often find that when I am writing, refactoring, or reviewing code that I want to do some simple testing. There are many existing test frameworks such as gtest and cppunit but my desire was to ...
2
votes
0answers
21 views
Google Mailer app inside Django using OAuth 2.0
I have built this Django Package which is an alternative for sending mail to users using Gmail API. Everything is working fine. But the verify(self, request) method inside ...
2
votes
1answer
74 views
Testing a template function in GoLang using mocking - making it DRY & easy to follow
TL;DR
I'm wondering how to organise test functions using mocks for GoLang drier & easier to follow.
Function
I have a template function that is very similar to ACF's getField:
It take's in a ...
5
votes
1answer
125 views
Hackerrank: Breaking the records
I'm learning Clojure and am a rank n00b at it, trying to learn from books and online tutorials (but I'm sometimes concerned that I am picking up bad habits or at least not all the good habits). For ...
3
votes
0answers
47 views
Building a GTD Productivity App Designed through Test Driven Development (TDD)
First, thanks so much for looking at my code. Over the past decade, I have tried every task management apps imaginable. I finally realized that the only way I would ever find my perfect productivity ...
3
votes
0answers
102 views
Jest - mocking a class function from an external node module
I am writing unit tests for a NestJS service, which imports and instantiates a class (OAuth2Client) from an external module (google-auth-library) and uses one of its functions (verifyIdToken).
I am ...
8
votes
1answer
500 views
Testing lower- and upper bound values in Python
Code functionality
The following code tests whether the values that a user specifies for a lower bound and upper bound on two properties:
The lower bound is smaller than the upper bound.
The values ...
1
vote
0answers
24 views
Microservice unit testing database script insert Error - H2 [closed]
For unit testing my ProductList service, I tried run a script to insert some data and then try to get this data and compare the list size.
But my database insert script is not running and returns null....
5
votes
2answers
104 views
Complex Numbers & Unit Tests in Python
I've just started a course that will require knowledge and experience with Python for future projects, which I don't have, so I thought I'd give it a go to familiarize myself with it and get some ...
5
votes
2answers
75 views
Ray implementation
Problem Statement/Context:
Represent a ray, given a origin and direction. Besides this a min_t and max_t value are defined. ...
1
vote
1answer
58 views
Test django URLs
I started learning Django and now I want to write some tests for my application. After reading some blog posts and watching youtube tutorials I wrote tests for URLs. Look at below.
urls.py
...
2
votes
2answers
77 views
Common Unit Testing Code – Follow Up
This question is a follow up question to the Common Unit Testing Code portion of my lexical analyzer questions.
My primary concern is the code in the header file and the C source file that implements ...
2
votes
0answers
56 views
Express compatible JSON Web Token authentication middleware
I am writing an Express.js middleware function in a TypeScript NodeJS project that uses a function from a third-party module to perform a small workload. When writing unit tests, I want to mock this ...
5
votes
1answer
76 views
Hand Coded State Driven Lexical Analyzer in C With Unit Test Part C
This review is presented in 3 questions due to the amount of code:
Part A contains the Lexical Analyzer and the main portion of the unit test code.
Part B contains the lower level unit tests called ...
4
votes
1answer
47 views
Hand Coded State Driven Lexical Analyzer in C With Unit Test Part B
This review is presented in 3 questions due to the amount of code:
Part A contains the Lexical Analyzer and the main portion of the unit test code.
Part B (this question) contains the lower level ...
8
votes
2answers
138 views
Hand Coded State Driven Lexical Analyzer in C With Unit Test Part A
This code review is presented in 3 questions due to the amount of code:
Part A (this question) contains the Lexical Analyzer and the main portion of the unit test code.
Part B contains the lower ...
3
votes
0answers
28 views
Command Line Utility for Starting Django Projects and Apps with Custom Files
What I'm Doing
I'm writing a command line utility for starting Django projects and apps with custom files.
The custom files build upon what Django offers, to make sure things like a custom auth user ...
3
votes
1answer
54 views
Granular vs a aggregated tests when dealing with arrays
I write code in a Test-Driven way and I often build my functions starting with tests for the easy edge cases.
For example, given a flat array of Items that have a <...
1
vote
1answer
80 views
Binary Search recursive & iterative solution
I have implemented binary search solution by using recursion and iterative approach.
I there any way to improve it?
Tests
...
-4
votes
1answer
51 views
Creating a Constructor used only for testing: anti-pattern? [closed]
I have a class which uses the Azure SDK. The class has two constructors, shown in pseudo code below:
...
6
votes
1answer
90 views
Tool for converting OEIS sequences into Desmos lists
https://github.com/CascadeIllusion/DesmOEIS
Recently began work on a Python project called DesmOEIS to build up my portfolio. It's a simple console program that looks up integer sequences from the ...
4
votes
0answers
59 views
Is there a better way to unit test a repository for a large aggregate root?
In our project we use domain-driven design and our customer aggregate root is large. The unit tests for the aggregate root itself are simple (~50 or so tests), but I am struggling with the repository ...
3
votes
1answer
34 views
Haskell Hspec/Quickcheck test for numeric function
I'm learning to use HSpec and QuickCheck.
As example I was implementing the Pseudocode from Wikipedia:Extended Euclidean Algorithm. You can find the project at github for the implementation of the ...
5
votes
3answers
121 views
CAN Bus testing
I am creating a Python 3.8 script that executes a series of tests that reads and writes information to and from a CAN bus network. I'm using the python-can and the cantools packages. I've managed to ...
1
vote
0answers
27 views
Cypress tests for Monopoly
I am creating Monopoly using react hooks. I am using cypress for testing it. The first test I have to create is to check about dice rolls. I have three tests in which I am repeating the same kind of ...
4
votes
2answers
73 views
Mock Atm program basic functions and xUnit unit test
For self learning purpose, I have created some xUnit unit test for these 2 Atm classes. At the moment, data is store in the in-memory object. This version is extended from previous version. For ...
1
vote
1answer
41 views
Testing Depth First Search Using Pytest
I have an implementation of depth first search, which I want to test using the pytest framework.
I would be making test cases for other graph algorithms, and would ...
2
votes
0answers
43 views
Finding, substituting and executing values in dictionaries
I wrote this code for finding, substituting and executing values in dictionary, much like $() bash operator works.
I used nested functions for this, forming ...
3
votes
1answer
135 views
In Memory Database in Unit tests, isolate the tests
I have stumbled across these unit tests in a code review that are using in memory db:
...
4
votes
1answer
127 views
Is this a good unit test for testing three types of mappings all at once?
This question is related to my previous two questions, in which I have implemented HashTable, and also SortedListMap and ...
4
votes
2answers
115 views
Sanity check a simple RPG character
I'm writing an assistant for the tabletop RPG Pathfinder in Java. I intend to use the MVVM pattern using JavaFX, possibly through mvvmFX. Before I go into the V-VM phase, I have built a first ...
1
vote
1answer
50 views
1
vote
3answers
66 views
high card game implementation
I wanted to write a simple implementation for a high card game. Basically two cards are drawn and the higher one wins. Additional rules: support for multiple decks, if same suits drawn then the ...
5
votes
1answer
592 views
Multiplayer card game “Hearts” with OOP in Python
To practice Object-Oriented Python and learning how to write tests, I found an exercise and solved it as below(all classes are put in one block of code to make the question a little bit more readable):...
4
votes
3answers
134 views
DistinctCount extension method
Here I go again. I have been finding a fairly common pattern in business logic code. And that pattern looks like this: ...