Junit test fails when run on package but succeeds when run on file


Jack

Major update: Has anyone encountered this before?

I am using JUnit 4.5 and Mockito 1.7 in a Maven project.

I have testCaseA.java in testCaseFolder package. If I open testCaseA.java, right click on the code, select "Run As" - "Junit Test" it works. However, if I right click on the package, select "Run As" - "Junit Test", it fails:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Misplaced argument matcher detected!
Somewhere before this line you probably misused Mockito argument matchers.
For example you might have used anyObject() argument matcher outside of verification or stubbing.
Here are examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"));
    at testCaseA.setUP(testCaseA.java:33) 

Line 33 is://MockitoAnnotations.initMocks(this);***//it said this is error***

Here is the code:

SomeService service;
@Mock
private CommonService commonService;
@Mock
public Errors errors;

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);***//it said this is error***
}

@Test
public void testvalidate() {
    //fail even here is empty
}
rone

What you got from the error update should be correct.

Your Mockito.when statement is wrong.

Mockito.when(commonService.get(Mockito.eq(contactGroupId))).thenReturn(disseminationProfile);

or

Mockito.when(commonService.get(Mockito.anyLong())).thenReturn(disseminationProfile); 

Related


Run a method if the test fails on Junit

Keva 161 I've added a method to my Selenium framework that takes a screenshot at the end of a test, but it doesn't run all the way to the end because some tests fail. I want to implement a rule to run this screenshot method if the test fails. It's just like: @

Run code when unit test assertion fails

Free Bird I am using assertEquals()it unittest.TestCase. What I want to do now is to call a function and do something in it when the assertion fails, I'm wondering if there is a way to do this? BartoszKP Normally, you shouldn't do this, but if you do want to,

Run code when unit test assertion fails

Free Bird I am using assertEquals()from unittest.TestCase. What I want to do now is to call a function and do something in it when the assertion fails, I'm wondering if there is a way to do this? BartoszKP Normally, you shouldn't do this, but if you do want to

Test fails when run using XCTool with logicTestBucketSize

otusweb I have a project with 1000+ unit tests and am considering using the parallelise option of xctool to speed up the build. So I turned it on and set logicTestBucketSize to 50. The test runs, but fails with some failures, which do not fail when this option

Run code when unit test assertion fails

Free Bird I am using assertEquals()from unittest.TestCase. What I want to do now is to call a function and do something in it when the assertion fails, I'm wondering if there is a way to do this? BartoszKP Normally, you shouldn't do this, but if you do want to

junit fails but passes when run via maven command line

Amma junitWhen I run with , I fail eclipse. But when I run it using the mavencommand line it succeeds. java.lang.ClassCastException: org.springframework.security.core.authority.GrantedAuthorityImpl cannot be cast to java.lang.Comparable at java.util.TreeMa

junit fails but passes when run via maven command line

Amma junitWhen I run with , I fail eclipse. But when I run it using the mavencommand line it succeeds. java.lang.ClassCastException: org.springframework.security.core.authority.GrantedAuthorityImpl cannot be cast to java.lang.Comparable at java.util.TreeMa

Generate report for junit when test method is run alone

Illidanek I have a Java project with JUnit tests running on Jenkins using Ant. By reading various tutorials online, I got all the tests to run individually. My build.xml looks like this: <target name="run_junit" depends="compile, ensure-test-name"

Generate report for junit when test method is run alone

Illidanek I have a Java project with JUnit tests running on Jenkins using Ant. By reading various tutorials online, I got all the tests to run individually. My build.xml looks like this: <target name="run_junit" depends="compile, ensure-test-name"

What happens internally when I "run Spring as a JUnit test"?

Shweta Gulati Even though my server is not running, I can still load spring beans and properties files when I run as JUnit Test. How is this going? Is a JVM instance created that compiles my test class? Also I haven't defined any classpath. What is the default

Generate report for junit when test method is run alone

Illidanek I have a Java project with JUnit tests running on Jenkins using Ant. By reading various tutorials online, I got all the tests to run individually. My build.xml looks like this: <target name="run_junit" depends="compile, ensure-test-name"

run a command, if it fails, run another, if it succeeds, end

Alan I'm trying to find a way to uninstall maya2019 from all studio workstations. We offer 3 versions of Maya2019 with different uninstall commands: "C:\Program Files\Autodesk\Maya2019\Setup\Setup.exe" /P {D4BE10F2-3E2D-4120-863A-765623D53264} /M MAYA /LANG en

run a command, if it fails, run another, if it succeeds, end

Alan I'm trying to find a way to uninstall maya2019 from all studio workstations. We offer 3 versions of Maya2019 with different uninstall commands: "C:\Program Files\Autodesk\Maya2019\Setup\Setup.exe" /P {D4BE10F2-3E2D-4120-863A-765623D53264} /M MAYA /LANG en

run a command, if it fails, run another, if it succeeds, end

Alan I'm trying to find a way to uninstall maya2019 from all studio workstations. We offer 3 versions of Maya2019 with different uninstall commands: "C:\Program Files\Autodesk\Maya2019\Setup\Setup.exe" /P {D4BE10F2-3E2D-4120-863A-765623D53264} /M MAYA /LANG en

run a command, if it fails, run another, if it succeeds, end

Alan I'm trying to find a way to uninstall maya2019 from all studio workstations. We offer 3 versions of Maya2019 with different uninstall commands: "C:\Program Files\Autodesk\Maya2019\Setup\Setup.exe" /P {D4BE10F2-3E2D-4120-863A-765623D53264} /M MAYA /LANG en

run a command, if it fails, run another, if it succeeds, end

Alan I'm trying to find a way to uninstall maya2019 from all studio workstations. We offer 3 versions of Maya2019 with different uninstall commands: "C:\Program Files\Autodesk\Maya2019\Setup\Setup.exe" /P {D4BE10F2-3E2D-4120-863A-765623D53264} /M MAYA /LANG en