Questions tagged [junit]
The junit tag has no summary.
48 questions
1
vote
3
answers
650
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 ...
6
votes
1
answer
3k
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 ...
-1
votes
2
answers
1k
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("...
-2
votes
1
answer
2k
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 ...
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 {
...
2
votes
1
answer
364
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 ...
-3
votes
1
answer
117
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 ...
0
votes
1
answer
100
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 ...
3
votes
3
answers
402
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 ...
0
votes
1
answer
806
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 ...
-1
votes
1
answer
418
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 ...
10
votes
3
answers
592
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 ...
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
-...
1
vote
2
answers
307
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 ...