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.

Filter by
Sorted by
Tagged with
3
votes
0answers
14 views

SmartUnit: Unit Testing with DI

I was thinking about how unit tests require you to manually instantiate all your dependencies, even though many of them are the same for every test or don't really matter (such as logging, where ...
2
votes
2answers
43 views

Mocking Interfaces Golang

I thought of doing the following to mock/test functions in Go and wanted some advice. Let's say you have an interface for a repository: ...
1
vote
1answer
64 views

Conventional C# for LinkedList with (non-)nullable references + xunit tests

I'm new to C# and would appreciate any feedback you might have on the following doubly-linked list implementation, particularly WRT the following language features: Exception handling Debug.Assert ...
2
votes
0answers
17 views

Interactive, real-time bikeshare web application with Bokeh

As a side project, I'm working on a Bokeh web application to display public bikeshare data on a map. The data is updated every 2 minutes using a periodic callback. Below is the full implementation. I'...
9
votes
5answers
2k views

Unit test for a maximum-finding function

A while ago, I got this question as a part of an interview test which asked to write a function to find the biggest number in a vector and write all the unit tests required to show that the code works ...
4
votes
0answers
42 views

Testing and coding conventions for testing C with SDL

I finished my first real C project and it was Conways Game of Life. The code is working fine and the game runs. Since this was my first project though I don't know any of the real code conventions for ...
2
votes
2answers
66 views

Python unit testing

I have started a hobby project and would like to integrate better and more thorough testing practices. Since I am not too used to it, I'd love to have some feedback on the sample code below. In ...
-1
votes
2answers
52 views

Should I add optional parameter to my function for test cases? [closed]

I have the function below, I want to access the context globally and I don't know if it's a good idea, I'm getting the context from the Application, I have TestAppliction in the test environment and I ...
2
votes
0answers
27 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
44 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
64 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 ...
2
votes
1answer
51 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
142 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
36 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
30 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
88 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
22 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 ...
5
votes
1answer
65 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 ...
5
votes
1answer
132 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 ...
6
votes
1answer
122 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
144 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
92 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
130 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
49 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
135 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
748 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
127 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
76 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
79 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
145 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
30 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 ...
2
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
82 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
53 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
92 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
60 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
36 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
125 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
28 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
78 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
42 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 ...

1
2 3 4 5
20