The junit tag has no usage guidance.
3
votes
4answers
101 views
Test cases do all the work through helper method — bad practice?
Consider a test suite like this:
public class MyTestSuite {
@Test
public void test_something() {
testHelperMethod("value11", "value12", "value13");
}
@Test
public void ...
0
votes
1answer
59 views
Reusing array with static test data across test classes
I have a Map which takes in an a String key, and an array of custom objects as the value. the map usually contains two entries, and the arrays for both entries never change in terms of data; once they ...
0
votes
1answer
218 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 ...
3
votes
3answers
107 views
Unit Testing a Function which produces “limit less” results
I am pretty new-ish to unit testing in a more nuanced sense. If have an application function which based on users given input could produce an seeming "limit-less"combination of output, whats the ...
4
votes
1answer
378 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 ...
1
vote
1answer
134 views
Multiple methods in single test case [duplicate]
I am new to Junit. I have a class with four methods. I am creating a test class with test cases. Can I have a test case that uses more than one methods of testing class or there should one test case ...
2
votes
3answers
215 views
Unit testing text output
I have recently become responsible for a legacy tool that analyses code and provides a log as output. As part of the JUnit suite for this, there are ~100 tests that rely on successfully matching the ...
2
votes
2answers
189 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, ...
1
vote
2answers
70 views
Verifying absence of an event in multithreaded unit test
I've got a legacy application that had a fragile unit test (which is really more of an integration test) that used a lot of Thread.Sleep calls to wait for events to happen.
While trying to introduce ...
0
votes
1answer
162 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 ...
-3
votes
1answer
121 views
How can I test a method which aggregates data from a database? [closed]
I'm developing the web Java application and come across the following issue:
I'm using jUnit 4.5.
Suppose that I have a method which aggregates data from a database for the rendering their to a ...
24
votes
2answers
3k views
Unit testing classes that have online functionality
When unit testing functions of a class that has private functions that require online functionality. How would one go about testing it?
For example:
public class Foo
{
public int methodA()
{
...
1
vote
5answers
2k views
Should each method have a seperate 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?
0
votes
0answers
41 views
Best practices for introducing testing to a large, stable, legacy Java application? [duplicate]
I'm working with a stable, but large legacy java application that is over 12 years old, maybe older.
Although the code has been upgraded to java 6, it's lacks the features above java 1.4 for the most ...
3
votes
2answers
1k 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.
...
0
votes
2answers
1k views
Where Are Multiple JUnit Test Methods Typically Placed in Code?
I've just read the Vogella JUnit tutorial and found it very helpful in understanding how to use JUnit. However, I'm a bit confused about what the convention is for placing multiple test methods in ...
3
votes
1answer
731 views
Do I need JUnit tests for the controller layer on a MVC when I have a database layer
I have a MVC which has this structure:
ui
controller
db
model
Basically the controller doesn't really do much more than connection ui with db layer.
Do I need to provide JUnit tests for the ...
3
votes
2answers
150 views
Is the use of JUnit feasible for a short duration project of around 3 months? [duplicate]
I work on projects which are usually of a duration, not more than 3 months.
Recently there has been a discussion about the use of JUnit in the projects.
There are activities being planned related to ...
2
votes
1answer
1k 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 ...
2
votes
3answers
5k views
How to write junit test case for the program [closed]
I have a method which has external dependencies within the method. Please help me in writing a junit test case for the below program.
@Override
public void methodToTest(String user){
...
9
votes
3answers
2k 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 ...
4
votes
3answers
16k views
How to test Java web applications
So far I haven't been testing or learning how to test my java web applications.
If you do, what are the tools you need, and is it really necessary to test a web application if doesn't need scaling or ...
1
vote
2answers
938 views
Submitting Java Code with Junit unit test
I have mostly worked on simple java programs and compiled and run them with Eclipse on Windows. So, I have no experience of using command prompt for compiling Java projects and do not have much info ...
2
votes
3answers
156 views
Should I care about Junit redundancy when using setUp() with @Before annotation?
Even though developers have switched from junit 3.x to 4.x I still see the
following 99% of the time:
@Before
public void setUp(){/*some setup code*/}
@After
public void tearDown(){/*some clean up ...
6
votes
3answers
632 views
Jenkins without Automated Tests
I know that Jenkins is focused on continous building/testing, monitoring of batch jobs about the project. We have a legacy project which such condition :
1)Has a development team.
2)It has SVN for ...
4
votes
2answers
259 views
Shipping test code as a form of sanity check
Have you ever shipped test code (JUnit, NUnit etc) with your application that could be runnable by the end-user ?
Basic Idea is this :
The application can be deployed in a varied environment and it ...
20
votes
4answers
3k views
How to drastically improve code coverage?
I'm tasked with getting a legacy application under unit test. First some background about the application: It's a 600k LOC Java RCP code base with these major problems
massive code duplication
no ...
7
votes
3answers
1k 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 ...