Skip to main content

All Questions

Tagged with
5 votes
4 answers
6k views

Extending the class to test it: is this testing approach fine?

I am curious if the following example of testing a class with protected methods is fine. For example, say you have the following class Foo that has method a() of return type Bar: class Foo { ...
oneturkmen's user avatar
0 votes
1 answer
85 views

Should all third party methods that access outside resources (like other databases) be wrapped up?

From the perspective of unit testing, the code under test should obviously not be accessing outside resources so the third party methods need to be mocked. However, it seems like this is poor practice ...
JobHunter69's user avatar
15 votes
5 answers
71k views

Unit testing a void method

In order to fix a bug in an application, I modified a method named postLogin by adding a call to an existing method named getShoppingCart. Code protected void postLogin() { getShoppingCart(); } ...
A_B's user avatar
  • 409
4 votes
2 answers
3k views

Unit Test : Do I need to make an unit test for each class in my project

I have recently tried to to implement unit tests on a Java Web Application my project is built on MVC design architecture and uses Spring & JPA Hibernate and JSF here is a package tree -src -...
Youans's user avatar
  • 481
0 votes
2 answers
303 views

How to I best test this method? Do I need to split it up?

Okay, please consider the following method. Let me first tell you that my goals of the method is to determine if file system assets exist. That's to say this is an internal company site where you'd ...
Paul Duer's user avatar
  • 139
4 votes
3 answers
4k views

How can I write unit test case of file format converter utility?

I have created one utility module which converts one file format to another one. File i.e. test.abc will be converted to i.e. test.pqr and internal format of files are totally different. This module ...
Akash Thakare's user avatar
3 votes
1 answer
12k views

Should I use a mock or create a new instance of an object in unit tests? [closed]

I have to write a unit test for a method like: void doSomethingWith(Country country) {...} There are the following classes: Interface: public interface Country { String getName(); ... // and a ...
Ales's user avatar
  • 39
11 votes
1 answer
15k views

Testing private methods as protected

I was reading this answer about testing private methods and it mentioned several possibilities: extract methods as public to another class make them public separate the env of test and production so ...
sam's user avatar
  • 221
4 votes
2 answers
3k views

Testing strategy for wrapper class

In my Android project I decided to create wrapper around SharedPreferences(which is basically key-value storage) with following interface interface Preferences{ public void saveInt(int value, ...
CheesyGnocchi's user avatar
0 votes
1 answer
286 views

Can JUnit be used to test this project?

I currently have an interesting situation occurring with my code, and after hacking away at what turned out to be a dead end for the last two weeks, I'm here asking those smarter than I to educate me ...
canadiancreed's user avatar
20 votes
7 answers
29k views

Should each method have a separate JUnit test class?

I am writing JUnit unit tests for my classes. Is it better to have a separate class for each method, or have just one test class for every actual class?
viraj's user avatar
  • 501
3 votes
2 answers
2k views

Unit testing to prove balanced tree

I've just built a self-balancing tree (red-black) in Java (language should be irrelevant for this question though), and I'm trying to come up with a good means of testing that it's properly balanced. ...
Darrel Hoffman's user avatar
2 votes
1 answer
2k views

JUnitEE vs JUnit

I know what unit testing is in general and what JUnit is in particular. But here I see that there is a project called JUnitEE which seems to me to be a wrapper over JUnit. So I would like to better ...
Geek's user avatar
  • 5,217
11 votes
3 answers
8k views

Mocking concrete class - Not recommended

I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended. Here some sample code of a unit-test for the ...
Mik378's user avatar
  • 3,916
8 votes
3 answers
5k views

What should I mock in tests of an application with service tier and DAO tier?

My classes are following this structure Service Tier (creates and maps InputDTO to DB Data) DAO Tier (actually executes DB calls) When I write service tier JUnit tests, the DAO tier is called, and ...
shinynewbike's user avatar