How to write Junit Test case for Private Methods in Java

preview_player
Показать описание

In this video, I explained different ways to How to write Junit Test case for Private Methods in Java.

keywords:How to write Junit Test case for Private Methods in Java,Junit for private method,Junit,private methods,core java,Junit test for private methods reflection,Junit Tutorial,Unit testing,Java,Automation,code quality,Junit eclipse,JUnit maven
Рекомендации по теме
Комментарии
Автор

Thank you so much, It's really useful 😍

gousmulla
Автор

nice explanation. useful to my project

subhanishaik
Автор

Thats really a good simple and useful explanation for dealing private method testing.
I have some suggestions and question.
1) shouldn't we use mock or spy for creating Library class object? or cant we?(line 25)
2) Do using reflection, it covers the method in main class while testing with coverage?

tathagatchaurasiya
Автор

IMHO: This approach only fits the scenario of you are not allowed to touch the code.
The other approach is to explain how to avoid such scenarios of complexe code like by using interfaces with several layers. This would allow to cut the complexe code into several pieces. Furthermore you can use mocks to work with. Ofc this goes hand in hand with already existing tests or just starting with a project, otherwise it's hard to refactor/to create new tests.
Btw: feeling something is hard to test often means the code is not written well. Thus a refactoring with another approach (architecture, design pattern or just rejuggle your method calls?) to improve the testability.

Pizzabeirut
Автор

Thank you so much for creating the video. Is this how I should pass two demensianl arrays to my method? : Method method = Solver.class.getDeclaredMethod("applyCycles", Array.class, Array.class); ? Also reflection does not work for me; I am doing so much work in my constructor, it takes a long time for it to run. Unless I create another constructor, but then that is almost like using a public method to call the private ones.

shawnmofid
Автор

But while writing junit we shouldn’t touch actual code? Please give another example

ashokkumar-cxof
Автор

Hello Sir, can you upload a video teaching how to write the JUNIT test cases for the methods(which has 2 or 3 business logics ) returning VOID?

bhaskarbanepali
Автор

Hi shiva., can you please upload power mockito tutorial?

ganeshparida
Автор

test cases always true i.e if i will give wrong input also it is passing ..some one help me in that

HemanthKumar-fuvh
Автор

What to do when we don't have any public methods in class

bhavanachimirala
Автор

Yo just wanna say that GOD loved the world so much he sent his only begotten
son Jesus to die a brutal death for us so that we can have eternal life
and we can all accept this amazing gift this by simply believing in him (Jesus) asking for the forgiveness of your sins
and forming a relationship with heavenly father.

zstar
visit shbcf.ru