问题
I'm building my package with maven (runs without problems) and then I try to make a Mockito test for a class.
Dependencies in the pom.xml are as follows:
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The mockito-test looks like this:
package Person;
import static org.mockito.Mockito.*;
import java.io.IOException;
public class AppTest {
public void test() throws IOException{
PersonManagement mockedPM = mock(PersonManagement.class);
//automatically creates an instance variable of type person
mockedPM.updatePerson("test","test");
//updates this.person
verify(mockedPM).updatePerson("test","test");
}
}
After launching mvn package the test results show, that no test were run (the file including the test is found and recognized, because when I put syntax mistakes there, compiler recognizes these)
I would appreciate any help, thanks
回答1:
Mockito is not a testing framework. It's a mocking API. Use JUnit or TestNG. These are testing frameworks. Both simply require some annotations to be placed on test methods.
And of course, your JUnit or TestNG tests will use the Mockito API internally, to mock dependencies.
回答2:
@JB Nizet told you the correct answer. You need to annotate the method with @org.junit.Test
回答3:
Mockito is a framework for mocking objects, while JUnit is a framework for unit testing.
it looks like you are experimenting with how it works. I would suggest starting by reading up on JUnit, and when you feel you have it under control, go back to how mocking works.
this is a dependency for JUnit:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
</dependency>
after adding and importing this you can annotate tests with @Test
来源:https://stackoverflow.com/questions/16122283/mockito-test-not-seen-by-maven