JUnit is a unit testing framework for the Java language.

learn more… | top users | synonyms

5
votes
1answer
59 views

Printing JUnit test results in file by changing and using the 'out' static variable of 'System' class

I'm building a framework for comparing files (in my own way) using JUnit. All test cases have been packaged in a JAR which is ran independently using a .bat file I ...
6
votes
2answers
87 views

Find number of plus in a 2d array

Problem CharGrid The CharGrid class encapsulates a 2-d char array with a couple operations. int countPlus() Look for a '+' pattern in the grid ...
3
votes
2answers
91 views

Determining if two Strings have common subtrings of a given length in Java

Problem: Given 2 strings, consider all the substrings within them of length len. Len will be 1 or more. Returns true if there are any such substrings which appear in both strings. Compute ...
4
votes
2answers
62 views

Unit testing Equals, hashcode and comparator - asserting contracts

After reading Joshua Blosh's Effective Java 2nd edition, I decided to implement equals, hashcode and comparable(where applicable) to every class I have been implementing. I have written a generic ...
1
vote
0answers
30 views

Testing a method which coordinates multiple objects

I have this class with one method, which uses three different objects to perform a task. ...
4
votes
2answers
86 views

DoublingQueue in Java

Inspired by this CR question, I decided to create my own queue! If you guys see anything taboo or have any improvements, please let me know. Ultimately I want it to be feature rich and bug free, with ...
11
votes
5answers
548 views

FiniteArrayQueue type with interface and unit tests

Doing some exercises on basic data structures, I learned about queues, and decided to roll my own to better understand how a basic queue can function. As the name indicates, this Queue is made from a ...
6
votes
1answer
114 views

Quadratic function solver + testing

I wrote a simple quadratic function solver with unit tests. Can anyone check if this is okay? Quadratic function class ...
5
votes
1answer
188 views

Serialization/Deserialization with Generics in Java

I've Implemented a Serialization Utility which Serializes/DeSerializes a class, along with writing JUnit Test Cases for the same. Please Review the code and Suggest me how to improve it. Particularly ...
5
votes
2answers
1k views

Unit testing private constructors and getter setters

I have a class Address, a class AddressTest and I am trying to write unit tests for its constructors and getter setters. ...
0
votes
1answer
176 views

JUnit test case to check that an exception of type javax.mail.MessagingException is not thrown

I have a method which will send a text mail using JavaMail API and I am trying to write a test case for this method which will check if an Exception of type ...
5
votes
2answers
68 views

BitSet wrapper to act as a sieve abstraction

This is a BitSet wrapper class to act as a Sieve abstraction for a prime calculator. Review for performance and Java/Java 8/Guava best practices. ...
3
votes
2answers
2k views

JUnit testing for Calculator in Java

I made a simple calculator. I would also like to write some simple unit tests for my CalculatorEngine class. I had to make some of my ...
7
votes
3answers
199 views

Understanding my permalink service tests

I started writing unit tests cases recently. For now, I created only "perfect case" where there is no error. However, the test seems to me difficult to maintain and difficult to understand. How can I ...
6
votes
1answer
122 views

Java 8 unit test for third-party data feeds

Use Case I have a service that does processing of records from multiple third-party feeds. The steps are generally identical for each feed, but each feed is populated in a different location on an ...
5
votes
3answers
241 views

Random letter test

My first test (randomUpperCaseLetter) checks if the returned random letter is an uppercase ASCII one. The second one (...
8
votes
2answers
474 views

Unit Tests for a Fraction Class

As my first Java homework, I wrote a class to handle fractions. This Fraction class implements basic operations for the fractions (addition, subtraction, ...
5
votes
4answers
975 views

Digital root recursive function

Haven't any experience writing recursive functions.(Generally tend to avoid them - not sure if that's a negative). What do you think about the following? This is also my first time using JUnit, I'd ...
4
votes
1answer
81 views

TDD and use case: cook dish with substitutions

This is code for a class that takes available ingredients and returns left over ingredients after making a dish. Cesars: 2 carrot 4 ice burg 1 chicken 1 beans Russian: 2 carrots 2 beans 2 chicken ...
2
votes
1answer
342 views

Generating HMAC

I had been working on several projects that required Header Message Authentication Codes to be generated when brokering files with 3rd parties like Netflix. Unfortunately on older systems like ...
2
votes
1answer
47 views

Tests for a POJO class ProgressableItem

I have tests for simple POJO class ProgressableItem (i.e. the one which has attributes total work and work done). I use JUnit 3 (it's from Android application). ...
1
vote
0answers
260 views

Testing with multiple input datasets and expectations

I wanted to make 3 test suites where each would run a test class with a specific input. I figured that in order to do this I could: Make an abstract test suite with all the variable parts (...
11
votes
4answers
3k views

Align Strings for Output

I wrote a class which can format input so that it is properly aligned. I'm interested in all suggestions (regarding structure, usability, style, naming, comments, etc). I'm especially wondering ...
4
votes
3answers
4k views

Unit testing a servlet in a meaningful way

I have to write a unit test for the method processRequest in the servlet below and I'm wondering if: It just shouldn't be done. The class should be rewritten / ...
4
votes
4answers
1k views

Using if else statements correctly

I have the following code, but I'm looking for a way to make the code read easier. ...
8
votes
1answer
7k views

JUnit extending abstract test class

I have been thinking quite some time and asked an StackOverflow question about extending abstract test classes, but I haven't been able to do it until now. I'll list my approach and then discuss some ...
2
votes
1answer
204 views

JUnit - Test whether object was persisted or not

I am using Hibernate 4 and Spring Framework 4. I wrote a simple test to check whether object was persisted or not. All set values in confirmationEntity are required. In this test I relly on that, ...
5
votes
1answer
85 views

JUnit Assert.assertSame

I am using JUnit, Hibernate and Spring Framework. I wrote a simple test to test whether entity was updated correctly or not. Is this correct way to test if entity was updated? Could it be done ...
9
votes
2answers
3k views

Create better Unit test

Question: Is there anything you could do in order to improve the test? I am using Spring Framework 4, Hibernate 4, JUnit 4. All DAO unit tests inherit from TestDaoSetup class: ...
24
votes
4answers
2k views

Just a lowly counter that turned out to be surprisingly complicated

While writing this review, I saw a need for a Counter object similar to Python's. It seemed like it would be easy to write such a class, but it turned out to be ...
8
votes
3answers
3k views

Simple Hello World with unit tests

This is a simple hello world sample project used for instruction. I'm just looking for general comments on the approach and design. AdvancedHelloWorldTest.java ...
4
votes
2answers
105 views

Review of java interface for constructing brain model

I have built a partial human brain model and the following is an example of how I use all the classes. I was wondering if anyone could critique my implementation strategies because I feel like the ...
2
votes
2answers
4k views

Mocking utility class for database testing

I have these classes that have a boilerplate way of initialization. So, instead of writing it each time, I wrote a class called MockUtil.java, and I put the ...
4
votes
2answers
574 views

Printing a diamond-shaped figure

How can I optimize this code to have fewer loops and return values for unit testing? ...
3
votes
1answer
156 views

Designing a listener method and making it Testable

I have a java based server application that needs to support multiple clients. In the main class I have a method that runs in an infinite loop and waits for client connection. Following is this ...
2
votes
2answers
5k views

Tesing a simple calculator class with JUnit/JMock

I'm playing around with JMock and trying to understand whether I understand the idea correctly. There's an interface Printer aimed to print integers somewhere. ...