Many times we need to create junit unit tests where we need to create temporary folders or temporary files for executing the testcase. Many times we rely on having a temp folder at particular location and generate all temp files there. Well, it has it’s own disadvantages. Major disadvantage is that you need to cleanup […]
In my previous post on this topic, covered writing the parameterized testcases with @Parameters annotation. If I pick the correct words then that approach was quite messy and not so readable. It required a lot of attention un-necessarily. Well, there is another approach using which you can write parameterized testcases in Junit with help of […]
Learn to test Spring security authentication using JUnit testcase using InMemoryDaoImpl. Also learn to build fully populated authentication object programmatically and then use it in application. SecurityContextHolder Spring security is based on security context, which is kind of static in nature. This essentially means that your do not need to inject its reference into your […]
Maven is a great tool for project dependency and build management. It can be used for running the Junit testcases for the project. In this post, I will show some simple but useful command examples to run testcases in various ways. For demonstration, I have created a maven java project using following command: mvn archetype:generate […]
Junit is a unit testing framework for the Java programming language. If you want to read about best practices followed for junit testing then here is an excellent guide for your reference. In this post, I am writing about writing junit testcases which will run only when a certain condition is met on runtime. For […]
Junit is a unit testing framework for the Java programming language. If you want to read about best practices followed for junit testing then here is an excellent guide for your reference. In this post, I am writing a sample test case which expects exceptions to be thrown on runtime. If it gets the expected […]
JUnit Test Listener – JUnit RunListener Example. JUnit also provide support for adding listeners while executing the tests via RunListener class.
JUnit test suites help to grouping and executing tests in bulk. Executing tests separately for all test classes is not desired in most cases. Test suites help in achieving this grouping. In JUnit, test suites can be created and executed with these annotations. @RunWith @SuiteClasses Read More : JUnit 5 Test Suite 1. JUnit test […]
In any application, which is being built incrementally, often it is desired that we should be able to run only certain tests whenever a new feature is introduced. This can be achieved using JUnitCore class of JUnit framework. JUnitCore is an inbuilt class in JUnit package and it is based on facade design pattern. JUnitCore class is […]
JUnit tests with timeout behavior. Also learn to use JUnit 5 test timeout using assertions. Junit test timeout using timeout attribute and timeout rule.
Writing JUnit ordered test cases is considered bad practice. But, still if you caught in a situation where test case ordering is the only way out then you can use MethodSorters class. 1. JUnit MethodSorters MethodSorters was introduced since JUnit 4.11 release. This class declared three types of execution order, which can be used in […]
In this JUnit tutorial, learn to create and execute junit parameterized tests. A parameterized test is normal test, which is executed over and over with again using different test parameters. It helps developer to save time in executing same test with different input types to test function robustness and possibly function boundaries. 1. JUnit Maven […]