Most voted "junit" questions
Popular unit testing framework for Java and Scala. The latest version, Junit 5, supports the new Java 8 added Features, for example lambda Expressions. Consider using in conjunction with the Java or Scala tag to indicate your use case.
Learn more…116 questions
Sort by count of
-
13
votes2
answers1652
viewsHow to perform TDD on the Service layer
I participate in a project that uses MVC layers with Hibernate framework persisting in a Postgres. Junit is used for testing and Mockito is used for mocking (I still have no knowledge and practice…
-
9
votes1
answer1077
viewsHow to run a group of suites in Junit?
I have the following suites below: @RunWith(Suite.class) // this other matters @Suite.SuiteClasses({ TestC.class, TestB.class, TestA.class }) public class MySuiteA {} @RunWith(Suite.class) // this…
-
9
votes1
answer766
viewsWrite unit tests for the interface or for the implementation?
Given the following test scenario, where I have the interface: public interface UserService { /** * Registra um usuário no sistema. * * @param user * Usuário à ser registrado. Não deve ser {@code…
-
8
votes3
answers2543
viewsUnit test with database
I have an application that uses JPA 2 with Hibernate behind and for unit testing, I use HSQLDB in memory with Junit 4.11. HSQLDB is configured in a persistence.xml file in a META-INF folder. My…
-
7
votes2
answers736
viewsWhat is the advantage of using Junit to test methods in a class?
I created an application that is basically a class that tests if the methods of another class are returning the expected values. My teacher asked me to remake this class as a Junit test case. I did…
-
6
votes2
answers944
viewsMock Static method with Demoiselle and Powermock/Mockito
I’m trying to mock a Static method, but Powermock requires the use of a specific Runner (Powermockrunner) for the Static mock to work! And for Demoiselle to work, you need to start Weld with…
-
6
votes1
answer304
viewsHow to simulate a logged-in user in an application with Demoiselle 2.4.2?
I have an app Demoiselle 2.4.2 already in operation that needs to use the SecurityContext to obtain the User currently logged in and make some decisions. The time now is to write the unit tests…
-
5
votes2
answers565
viewsWhat kind of tests can I still do on that code?
I’m doing a sequence of tests in a simple bank application, but I don’t know what kind of test I can do on this system to cover 100% of the code, it’s only covering 61%. I’ve done all the tests with…
-
5
votes1
answer3287
viewsError using Mock: Wanted but not Invoked: Actually, there Were zero interactions with this mock
I’m making a list of exercises and I’m having doubts on the following: Question 3 - The Verify method, from the org.mockito.Mockito.Verify package, is used to check the amount of times a method is…
-
4
votes0
answers890
viewsFill CPF + Data field with java webdriver Selenium mask
I’m having trouble filling in Date and CPF fields with mascara via id or xpth in Selenium+java+Junit. Does anyone have any idea how to do?. NOTE: I don’t want to generate CPF...I want to fill out…
-
4
votes3
answers1738
viewsIs it possible to test only specific classes?
I have two classes of tests: class A { @Test public void fazAlgo(){ // ... } } class B { @Test public void fazAlgoMesmo(){ // ... } } My tests are taking too long because all classes are being…
-
4
votes2
answers567
viewsTest without "fouling" (adding data) the database
I am having trouble doing integration testing. I test my database functions. My web application does not use any framework database connection and I am unable to do tests without fouling my…
-
4
votes3
answers1850
viewsHow to test the Service layer in a web service application, using mockite and junit
I have a class of services that will receive a dependency injection from an object responsible for the persistence layer. In this service class are all my methods that will answer the web service’s…
-
4
votes1
answer566
viewsDemoiselle 2.4.0: Error running test with Junit
I have a project built from the archetype of Demoiselle for Maven. The generated application is the one that exemplifies the Demoiselle, containing a register of bookmarks. The programmer who…
-
4
votes2
answers341
viewsDoubt in a Java exercise
I was looking for some Java exercises to train and learn some algorithms when I came across the site exercism. and I decided to do their Java exercises. So far so good, I downloaded their app using…
-
4
votes2
answers95
viewsWhat is the best way to define access to the methods of a class I want to use for unit testing?
I have a class Runnable, that does a lot of things in my system. When I created it, I didn’t want to instantiate its methods out of her scope. That’s why I wrote the methods like protected. Now, I’m…
-
4
votes0
answers207
viewsHow to make a mock in an android class at runtime?
I am having a certain difficulty in the tests, I wanted to know if there is a possibility to simulate a custom return in a method at runtime example: @RunWith(JUnit4.class) public class TesteSmile {…
-
4
votes2
answers2567
viewsJunit Eclipse Error: "No test found with test Runner Junit 5"
I’m not being able to run my tests in Eclipse, below is a simple test that doesn’t work: import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class…
-
3
votes2
answers1288
viewsExecution cannot find 'org.junit.Assert' even if you have the Junit jar in classpath
I have a problem that I’ve done a lot of research on and I haven’t found the answer to yet. I have a test case I’m trying to run and send a message to the console. But even though he has Junit’s…
-
3
votes1
answer373
viewsHow to change the language of the exceptions released during automated testing
Using Eclipse (IBM RAD Studio), Maven, and Junit, when an exception is released while running the tests the message is shown in English. I would like it to be shown in English. Example:…
-
3
votes2
answers2051
viewsDevelop integration tests correctly
We are writing several tests for the application, there are testes unitários and we started testes de integração. All communication with DAO is mocked, but when I test the API I should re-test the…
-
3
votes1
answer201
viewsError accessing dao class by test class
I have the following error, when accessing a dao class of a test class: java.lang.Nullpointerexception This is the controller method: @Post("/consultar_lancamento/{codLancamento}") public int…
-
3
votes2
answers782
viewsHow to use JUNIT to test void methods of my DAO class
Hello I have a DAO class and I want to implement tests with JUNIT, but many of the methods have the return void. Here’s a piece of the class that makes up the DAO package public class ExemplarDAO {…
-
3
votes2
answers1864
viewsJunit 5 - How to run a test method only if another test method passes?
It would be something like that: @Test void metodo1() { assertTrue(...); } @Test void metodo2() { //Deve ser executado após método1(), e SOMENTE SE metodo1() passou! assertTrue(...); } I need to do…
-
2
votes1
answer60
viewsAndroid Test - Call Method
I wonder if in android Unit test would have the possibility to call isolated methods of code, or if only calling activitys, buttons... I searched several places and found nothing talking about…
-
2
votes1
answer73
viewsTesting RMI with Junit
How to test a client/server application using RMI with Junit? I’ve searched a plethora of places and found nothing to help me.
-
2
votes1
answer331
viewsCreate a web application that runs Junit test cases on java files that will be submitted by a page?
I’m trying to create an application that looks like a judge online, but all I want is that after submitting a java file through an html or jsp page, the application runs a certain Junit test case on…
-
2
votes2
answers5233
viewsHow can I test method with void return using Junit?
It is possible to perform automated testing, in Java, of a method that has return void using JUnit? If yes, how is it possible?
-
2
votes2
answers294
viewsHow does Junit work?
How does the Junit open-source framework work? Does it guarantee the quality of the software? It is recommended to write unit tests on a daily basis?
-
2
votes1
answer147
viewsWhere to store binary files in Junit Unit tests with Maven?
I have the following directory structure for the Unit tests Resource folder: src/test/resources/*.files So that I can read binary files (like a PDF for example) to complete a Unit test, I am…
-
2
votes0
answers257
viewsHow to write the Junit test with Spring Autowire?
I am currently setting up a Dynamic Web project to run unit tests, but this project is using dependency injections by Spring Frameworks, it is important to mention that the version of spring that…
-
2
votes1
answer430
viewsUnit tests on a CSV file upload
Before explaining my problem I will show my CSV file upload code. public String uploadArquivo() { try { removeInSession(LISTA_TIPO_INDICIOS); removeInSession(LISTA_INDICIOS);…
-
2
votes1
answer83
viewsEAD: Configuration error while running tests
I downloaded the videos from the site for studies, in the video of Modulo3_video3, about Configuration, I got an error running the test after using the Configuration feature. 1 - I added the file…
-
2
votes1
answer374
viewsHow to test java exceptions using spring and Junit 5 lib?
I’m in doubt about how to test my java exceptions using the Spring Framework’s own resources. I’m testing a class called UsuarioValidator.java and in it I have a method called…
-
2
votes1
answer275
viewsWhat is the point of using Assert.assertNotNull() in frameworks?
I have seen in the Spring Boot framework that they use a lot of Assert.assertNotNull() to validate the variables if they are receiving null values. It is correct to use this same approach in…
-
2
votes2
answers895
viewsJunit unit test for default system routines
I have a Java code that checks if there are standard categories registered in the database, if yes it returns true, if he doesn’t return false. public boolean validaEntradaDeDadosPadrao() {…
-
2
votes1
answer680
viewsGson Library Changing useful. Date
When using the library GSON for the manipulation of JSON, I realized that by doing the parsers the date is being changed, it’s tiny, but it’s enough to break my unit test with JUnit. Follow a sketch…
-
2
votes1
answer584
viewsTest with junit
I developed a simple Bank system, now I want to know how I can use Junit only in the ways to withdraw and deposit. package CaixaEletronico; import java.util.Random; import java.util.Scanner; public…
-
2
votes1
answer72
viewsHow to use junit to test Jax rs in wildfly
I created the following test to validate the registration but instead of returning 201 with the created resource is generating this generic error. My DAO is running on its own in a normal way (I…
-
2
votes1
answer201
viewsError while deleting data in Mysql by Java
In the database I have three tables, where one of them keeps the foreign keys. Error made: Error: com.mysql.jdbc.exceptions.jdbc4.Mysqlintegrityconstraintviolationexception: Cannot delete or update…
-
2
votes1
answer2219
viewsAssertThat method and use of Matcher
To perform unit tests using the method assertThat in Junit, you need to pass an object Matcher as a parameter. public void assertThat(Object o, Matcher matcher){ ... } An example of using passing an…
-
1
votes1
answer903
viewsHow to resolve the error Caused by: java.lang.Nullpointerexception in getSessionFactory()
Is popping this error message for me Here are the lines that gave error: public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static…
-
1
votes1
answer669
viewsHow to configure a project with Junit to be able to build correctly inject Entitymanager?
I have a legacy JSF/Demoiselle 2.4 application that lacked the good practice of building unit tests. In order to meet new requirements, I have implementations to do and I intend to build them using…
-
1
votes0
answers69
viewsHow does mock work in integration testing?
How to use mock in my integration tests?
-
1
votes1
answer975
viewsHow to test a DAO (using Spring and JPA) out of a container?
I am developing an application with JPA 2, Spring and JSF 2 running in Wildfly 8.0.0. I have developed some previous applications following this same specification but never tested properly using…
-
1
votes1
answer104
viewsMethods to test Spring application are not found
I am following the following article: Introduction To Spring MVC Test Framework I have the following code: this.mockMvc.perform(get("/product/1")) .andExpect(status().isOk().…
-
1
votes1
answer803
viewsJunit with spring Autowired
I have a big problem that in my Genericservice I use an @Autowired on an Httpservletrequest (Even not knowing the utility, because, I do not know the architecture so well), and needed to use unit…
-
1
votes1
answer67
viewsRun unit tests with dependencies that are in the exclusions group
I have a scenario where I need to run a test with Junit in a feature that has an external dependency, but to run this functionality on the application server I need to put this external dependency…
-
1
votes1
answer1526
viewsCalculate delta value for assertEquals in Junit
Greetings. How best to calculate the delta value of Junit’s assertEquals(message, expected, actual, delta) method?
-
1
votes1
answer404
viewsNo tests found with test Runner 'Junit 4'
When creating a new package and within that package create a new test when trying to run the test the eclipse returns the message: "No tests found with test Runner 'Junit 4'" Within the project I…