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.
973
questions
1
vote
0answers
20 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:
...
0
votes
0answers
12 views
Java unit test Mock simulate file [closed]
I made a little game called Space Invaders, a working example you can find here: https://github.com/Koffiemolen/SpaceInvaders.git Go for the second branch, SpaceInvadersV2.
In the module dataaccess I ...
1
vote
1answer
54 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
76 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
14 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
59 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
63 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
126 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
116 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 ...
7
votes
1answer
133 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
66 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 ...
4
votes
1answer
91 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
43 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
70 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
294 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
23 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
83 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
45 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
75 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
43 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
126 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
79 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
50 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
84 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
33 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
118 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
26 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
72 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
34 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
125 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
110 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
64 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
388 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: ...
5
votes
0answers
40 views
Using an extra mock simply to take advantage of the behaviour observation tooling
I'm writing integration for a project, but our framework doesn't provide any ability to inject dependencies, so I've written tests with a unit testing framework (GTest) and used a mock (GMock) in an ...
2
votes
0answers
33 views
NavigationBar component with hooks. Can it be made more readable/maintainable?
I wrote a NavigationBar component in React, using hooks, react-bootstrap, react-i18next and css. Now the component works as I expect it, but the code seems ugly. (I'm new with hooks)
Features:
It's ...
9
votes
1answer
162 views
Secure ADODB: Unit of Work
I've been meaning to revisit this old code for a long time, and this week finally ended up doing it. The resulting code is on GitHub, and for full context and disclosure I wrote a blog article about ...
4
votes
2answers
500 views
Increment values in a dictionary
In my continued venture to teach myself C# I came across an exercise using Dictionary. I created a class that has a method. In that method it creates a dictionary with keys/values. A string is ...
4
votes
4answers
82 views
PropertySet implementation
Problem Statement:
Store properties with a certain name (key), type and value. The key is always a character literal and the value can be of type bool, ...
0
votes
0answers
19 views
Parametrize pytest test suite to work for mutiple classes
Context:
I am working on a package which lets users access credentials (stored with a defined structure) from a database. The "database" can be a real KeePass database or other text based formats like ...