Wants to understand how @Tested works with JMockit

て烟熏妆下的殇ゞ 提交于 2019-12-22 07:59:49

问题


I am using JMockit since long.I would like to understand how @Tested works.

Today i was trying to use it within my Test class. What i understand is Whatever class we wants to test we can mark it as @Tested.

One thing which was confusing me about the behaviur of this is when i try to set something in @Before.Below is my query.

My Class for which i want to write Test case

public  Class A{

    public A(){}

}

Test class

public class ATest {

    @Tested
    private A a;

    @Before
    public void setUp(){
        a.setSomething();
    }

    @Test
        public void testA(){
    }
}

In this case i get NPE. But if i use the same block of code in my test method directly that just works fine.Can anybody help me to understand the behavior of @Tested. I am using Jmockit version 1.17

I have also checked the post on GitHub as below: https://github.com/jmockit/jmockit1/issues/168 i just wanted to confirm is it also fixing my problem?


回答1:


I was able to find what i was looking for http://jmockit.org/api1x/mockit/Tested.html#availableDuringSetup--



来源:https://stackoverflow.com/questions/30868690/wants-to-understand-how-tested-works-with-jmockit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!