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
-2
votes
0answers
26 views

Which of these is a better practice to write Python unittest for CRUD operations of REST api? [closed]

I have a python class that has methods to perform the CRUD operations via REST api: ...
3
votes
2answers
174 views

Mocking pathlib.Path I/O methods in a maintainable way which tests functionality not implementation

I have a function that constructs a path based on a function of inputs and creates the parent directory. When writing a unit test for this function, I want to mock the I/O part of the function, ...
-2
votes
2answers
85 views

Episode 1: Mastering code and Testing it [closed]

Once upon a time there was a noob developer who learned it all by himself because he grew up in a nation far behind in IT. I've tried to learn C# for about 5 years, without any improvement over the ...
0
votes
1answer
85 views

Asking for test: Calculator function javascript

I have made a code that can run a calculation from text. When I tested it, I didn't find any bugs. You are sharper than me. Maybe you can discover some bugs in this code. When you know some ...
-1
votes
1answer
59 views

Unit testing an unspecific order of method calls [closed]

I cannot figure out how I am supposed to unit test the implementation of GetFilteredEntites(IEnumerable<MyEntity> myEntities). ...
3
votes
0answers
94 views

UPDATED: Ambient time context to help unit testing

The following test demonstrates the functionality of Time class which is supposed to be used instead of DateTime.Now. You could ...
1
vote
0answers
19 views

Document storage models and Django Unit Testing

My question is about proper testing procedures for Django models. The project is for a startup building a very basic HR system due to excel sheet data integrity problems. I am trying to figure out the ...
5
votes
2answers
224 views

Test on remove function

let's say I want to create a 'utils' package with several functions working on files and folders. I want to do it once properly so I can use them in all my personal projects without feeling to re ...
3
votes
1answer
48 views

Basic Unit Test of Application Service, setup and cleanup methods

I'm not experienced with testing, therefore I'd like you to look at my code proposal of unit test. My solution has following projects Tests\Application.Tests Application Domain Infrastructure Web ...
11
votes
4answers
1k views

Binary Search given sorted array Unit test

I have implemented Binary search code for a given sorted array, written unit test too, Please review my BST unit test code and let me know your comments for improvements. ...
0
votes
0answers
59 views

More assertions about data in infrastructure code as unit tests

This question is related to this other one that I asked yesterday. I have some Python code to make assertions about YAML data in AWS CloudFormation templates as follows (simplified): ...
2
votes
1answer
44 views

Assertions about data in infrastructure code as unit tests

I have some Python tests I have written, but these are for making assertions about data in infrastructure code (AWS CloudFormation templates). I am using the Unittest framework. I have code like this:...
4
votes
0answers
64 views

Source Control and Unit Tests

Context This post will be related to the code request I asked for, some time ago. I would like to focus this time not strictly on the implementation of the ...
12
votes
0answers
110 views

Open source project to ease the Assert part from the functional tests of .Net Core Web APIs

I have built an open-source project based on FluentAssertions in order to solve some recurring tasks I was doing while testing the .Net Core APIs I'm developing. I find the capability of doing in ...
1
vote
1answer
89 views

Unit Test class from iOS

I am learning to write test cases in iOS using Swift. I was stuck at testing static functions from my Utilities class, so I ...
5
votes
3answers
196 views

Mars Rover technical Challenge in OOP

I am trying to practice OOP and TDD concepts, I have written this code for Mars rover challenge from marsrovertechchallenge . Can you please review my code from my GitHub repository? Or you can ...
2
votes
1answer
61 views

Unit tests of matrix arithmetic

Is this good way of creating tests? I have no experience how they do it in companies. Ignore uppercase names of variables.. I may change it eventually. ...
7
votes
3answers
232 views

Unit testing a REST API in Go

I am learning Go by writing a simple CRUD REST API using gotilla/mux and Gorm. I would like to get some feedback on the application code and on unit tests in particular. Please suggest me what to ...
7
votes
2answers
1k views

Move all zeros to the left with TDD approach

The task Given an integer array, move all elements that are equal to 0 to the left while maintaining the order of other elements in the array. Let's look at the following integer array. ...
1
vote
2answers
51 views

Unit Test BST in Java

I have written BST in Java for practice. How can I write better unit test cases. I am sure the way I have written them is not proper. Code for BST ...
5
votes
2answers
131 views

classes to represent a HTTP request and response in C++

I am writing an HTTP message coder/decoder. In my decoder I parse http messages into a http_request or http_response. In my encoder I encode one of these classes. Representing the messages is the ...
8
votes
1answer
118 views

Writing a test to validate that the repo is formatted

I have a short test to validate that all committed files in the repo are formatted. I'm new to go so not sure what the best wat to do it is. The error handling, in particular, is rather gruesome as ...
2
votes
3answers
107 views

Unit tests code for a Java class that that checks whether an array is sorted

I'm trying to write unit tests code for a java class. The class tests an array for sorted (either way) or not. Here is the Unit Tests code: ...
1
vote
0answers
38 views

Message handling: Should a test/spec do it?

I am currently implementing an app that uses an architecture based on features & usecases and message sending. Features are created with message handler passed in. To test the feature, a handler ...
2
votes
1answer
61 views

A simple priority queue in Java via linked list sorted by priority keys

Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
1
vote
2answers
115 views

Unit tests for anagram finder

I did this test for a job and the feedback was: "while many were added to test private methods, they did not do anything to ensure the public interface worked correctly, edge cases were missed" But ...
2
votes
1answer
68 views

Rustacious way of checking if string ends with any suffix from a selection

What's the best way to check if a String ends with any of multiple suffixes in Rust? I have a working, naive solution: ...
2
votes
0answers
76 views

Tests for redis wrapper

I've written a wrapper package for redis. The idea is to be able to provide better error reporting with the package, as well as integrating stats and logging at a later stage. For now it's just better ...
3
votes
3answers
107 views

BindableBase with a throttle

I have project where I'm using BindableBase for my INotifyPropertyChanged implementation. Some of my objects however are ...
5
votes
1answer
35 views

CandidateArchive for model-assisted multi-fidelity global search algorithm

For my research I'm working on global search methods where a candidate solution can have it's fitness (=score) evaluated in multiple fidelities (=accuracy levels). The goal of the ...
4
votes
1answer
183 views

PyTorch Unit-testing in Python

I'm new to PyTorch and I'm writing a unit test for an activation function I'm making. I plan to test against a reference implementation for this function. I want to approach this in a test-driven way,...
3
votes
0answers
71 views

Sending push notifications to a user

I have a function whose responsibility is to send a push notification to a user. I call this function from a view in flask framework. I have read multiple articles around refactoring and good designs ...
1
vote
1answer
67 views

Idiomatic way to write proper F# (x)unit + fsunit tests?

I am writing some unit tests using XUnit in F# and I am wondering what is the most idiomatic way in the F# sense to write them. Let's start a simple case: ...
10
votes
4answers
2k views

AsyncDictionary - Can you break thread safety?

This class is an Async/Await wrapped Dictionary. Of course it doesn't technically implement IDictionary, but the functionality is basically the same as an IDictionary. It achieves similar ...
5
votes
1answer
170 views

Implementing d-ary heap

I'm trying to Implement a d-ary heap. A d-ary heap is just like a regular heap but instead of two childrens to each element, there are d childrens! d is given when building a heap, either by giving an ...
1
vote
0answers
83 views

Building maps for Dgraph integration tests in Java 8

I want to refactor this in Java to reduce my code duplication. ...
4
votes
2answers
107 views

Ensure difference between sets

An endpoint that my application interacts with allows you to specify which fields are returned in the JSON result. My application will then map the JSON to a POJO using Jackson. Quite often I add more ...
2
votes
0answers
41 views

Laravel testing for compatibility between old and new password-hashing schemes

I currently have an event listener tied to Laravel's Attempting class. The listener is designed to rehash an old password to something newer. The current DB stores ...
16
votes
3answers
2k views

ExactlyOne extension method

I often find in codebases something on the order of if (sprockets.Count() > 0) which is easily replaced with LINQ's ...
9
votes
2answers
1k views

Recursive search on Node Tree with Linq and Queue

This code is now maintained on GitHub I've created a Node class which contains two important properties: ...
12
votes
2answers
1k views

Calculating Fibonacci sequence in several different ways

I'm doing an experiment trying to freshen up my unit-testing and learn dynamic programming. Every test passes but I'm curious of the result of some of them and worried if I'm doing the testing ...
3
votes
3answers
111 views

Unit tests for a function that calculates demerit points for speeding

I'm currently working on a unit testing course (NUnit 3.x). I've been tasked with a simple class to test all edge cases. ...
1
vote
1answer
101 views

Bowling Kata in Java

I am sharing my Bowling Game Score Kata made in Java, it is available for whoever wants to code review it. I appreciate any comments. ...
0
votes
1answer
106 views

Abstracting an Email Notification Service & testing the the logic of the used abstract factory

In my application I have an Interface IEmailNotification that represents an Email and the concrete implementations have nothing to do with ...
1
vote
0answers
30 views

Clojure test for Git operations

Is this code a good test for a testable Clojure code? ...
2
votes
1answer
62 views

Table class to fill array structure with values

The code creates a table and adds rows and columns. Does it make sense to write the code like this? Would you design it differently? Is there a better OOP approach to this? ...
1
vote
1answer
48 views

Test Driven Development Roman Numerals php

I just learned about Test Driven Development on a podcast yesterday. So I decided to try it out today by writing a roman numerals to integer converter (per their suggestion). I've never written Unit ...
3
votes
2answers
104 views

Simple OOP currency converter - follow-up

This is a follow up question on this post This is what I changed on my previous code: I use Exchanger and PairCurrency class ...
1
vote
1answer
54 views

Creating a real unit test in Karma for Angular code [closed]

This is a piece of test code made for the Angular application. The router object is a mock provided by the RouterTestingModule dependency. I wonder if such a test can be considered a unit test (...
8
votes
2answers
492 views

Simple Unit Test in C

Simple UnitTest macros utility in C. I decided to make this to be able to more easily organize my tests and I emphasized on readability. Please tell me what you think and if this utility would perform ...

1 2 3 4 5 19