Questions tagged [junit]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
3 answers
195 views

Java design approach for "duplicated" class that are identical, except the import sources are different

So I have two identical classes, say ClassA and ClassB. In both classes, they operate on the same kind of data classes, and the method bodies are exactly the same. The only difference is that the ...
kroger9's user avatar
  • 25
4 votes
1 answer
2k views

Is performing integration tests on a production DB a bad practice?

I'm writing integration tests for an already existing product. I'm using the Spring Integration Testing suite for this purpose, which allows testing a real DB connection by creating a transaction and ...
Christian Vincenzo Traina's user avatar
-1 votes
2 answers
572 views

Assert same and equals in unit test

I have a function to be tested fn doNothing(Student student) { //do some other operations here. but student is unmodified return student; } And my unit test is var student = new Student("...
Santhosh Thamaraiselvan's user avatar
-2 votes
1 answer
1k views

What's the reason for wiremock instead of Mockito in integration tests [closed]

I enjoyed the process of writing an integration test for a system that relies on http, by mocking such end-points with Wiremock, and I feel upskilled, having wrestled with Matchers. Now, Wiremock as a ...
HellishHeat's user avatar
5 votes
4 answers
4k 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
2 votes
1 answer
295 views

Changing a class with static dependency injection to allow unit testing

I'm new to JUnit/Mockito and to unit testing in general. I'm asking this question in order to get feedback and learn best practices/patterns/strategies. I wrote a class but when came time to unit test ...
totsubo's user avatar
  • 129
-3 votes
1 answer
87 views

Selenium and Junit: Does it make sense?

Simply, given that Selenium is a testing tool, it seems redundant to combine Junit with Selenium tests. Does one write the Selenium test and then a separate Junit test of the Selenuium test or should ...
releseabe's user avatar
  • 519
0 votes
1 answer
48 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
3 votes
3 answers
335 views

Why are test frameworks like JUnit or TestNG not more "object-oriented"?

By "more object-oriented", I mean, it appears to me testing frameworks like TestNG and JUnit could encourage testers to write implementations of Test and TestSuite interfaces. The current approach ...
Benjamin Berman's user avatar
0 votes
1 answer
745 views

Why did JUnit declare setUp and tearDown in camelcase, even though each of them is a single word?

Reference: http://junit.sourceforge.net/junit3.8.1/javadoc/junit/framework/TestCase.html#setUp() setUp should have ideally be named as setup I've explored if any duplicate method setup is used in ...
kai's user avatar
  • 245
-1 votes
1 answer
383 views

Given an implementation of a Service Layer and Repository layer, should you make tests of both?

Currently I have an entity called Product with the respective ProductRepository and ProductService. For ProductService, I have tests for: Read (Covering Create too) Update Delete Besides achieving ...
0xFED5550's user avatar
  • 107
10 votes
3 answers
559 views

Are manually writing unit tests Proof By Example?

We know that writing JUnit tests demonstrates one particular path through you code. One of my associates commented: Manually writing unit tests is Proof By Example. He was coming from the ...
hawkeye's user avatar
  • 4,819
15 votes
5 answers
68k 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
2k 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
  • 451
1 vote
2 answers
272 views

When writing a JUnit test for non-covered legacy code - how important is it to understand the original scenarios?

A Tech Lead in my team said: We're going to use sonar on our (500KLoc) codebase so that everytime you do a commit, it will check the classes you've touched against the coverage goals. If you don't ...
hawkeye's user avatar
  • 4,819
6 votes
1 answer
129 views

What is the method to articulate the tradeoffs between short-fast mocked JUnit tests and slower Integration tests?

The assumption is that we're working on a large legacy Java codebase - with active ongoing development. I had a team member say: We should use lots of smaller JUnit tests that are focused on one ...
hawkeye's user avatar
  • 4,819
5 votes
4 answers
5k views

Should I put UI and logic in separate classes?

I currently work on a hobby project which I use to learn more about Android/Java programming and programming in general. Recently, I decided to integrate jUnit into the project. Just getting it in ...
Namnodorel's user avatar
0 votes
2 answers
296 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
0 votes
1 answer
779 views

Why is JUnit called a Framework?

Citing JUnits homepage: "JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks." According to a the answer of this question: ...
Mostafa Mahdieh's user avatar
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's user avatar
  • 405
10 votes
4 answers
6k 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 ...
Attilio's user avatar
  • 487
8 votes
1 answer
7k views

Writing a valid test case for validating XMLs

How would I write a unit test, say JUnit, for validating an XML file? I have an application that creates a document as an XML file. In order to validate this XML structure, do I need to create an XML ...
Mohammad Najar's user avatar
3 votes
1 answer
980 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 ...
jbailie1991'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
3 votes
3 answers
372 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 ...
Shane Andrie's user avatar
10 votes
1 answer
14k 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 ...
sam's user avatar
  • 211
1 vote
1 answer
5k 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 ...
want2learn's user avatar
2 votes
3 answers
3k 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 ...
Rossiar's user avatar
  • 157
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
1 vote
2 answers
147 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 ...
Steve Mitcham's user avatar
0 votes
1 answer
285 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
-3 votes
1 answer
584 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 ...
St.Antario's user avatar
23 votes
2 answers
4k 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() { ...
Ben Crazed Up Euden's user avatar
19 votes
7 answers
28k 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
  • 491
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
0 votes
2 answers
3k 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 ...
Thunderforge's user avatar
  • 2,708
4 votes
1 answer
2k 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 ...
Nikola's user avatar
  • 367
3 votes
2 answers
263 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 ...
Ankit's user avatar
  • 949
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,187
2 votes
3 answers
10k 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){ //...
Pradeep's user avatar
  • 313
11 votes
3 answers
7k 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,888
7 votes
3 answers
28k 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 ...
OnlineAlien's user avatar
2 votes
2 answers
2k 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 ...
mu_sa's user avatar
  • 217
3 votes
3 answers
232 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 ...
c_maker's user avatar
  • 8,280
7 votes
3 answers
991 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 ...
lionme's user avatar
  • 73
4 votes
2 answers
426 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 ...
Newtopian's user avatar
  • 7,201
25 votes
5 answers
21k 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 ...
Peter Kofler's user avatar
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