All Questions
15 questions
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 {
...
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 ...
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();
}
...
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
-...
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 ...
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 ...
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 ...
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 ...
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, ...
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 ...
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?
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.
...
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 ...
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 ...
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 ...