应用程序目录/软件包结构是下一个:
scr/main/java
-mockitoinit.controller
-mockitoinit.model
-mockitoinit.repository
-mockitoinit.service
-- AppInterface.java
-- AppIntefacaImpl.java
scr/test/java
-mockitoinit.service
--AppInterfaceImplTest.java
AppInterfaceImplTest.java代码如下:
package mockitoinit.service;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class AppInterfaceImplTest {
private AppInterface app;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@Test
public final void test() {
assert(true);
}
}
因此,当我执行mnv编译器:testCompile时,它将失败。日志如下:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Init Mocks 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mockitoinit ---
[INFO] Deleting C:\Users\arturo\eclipse_tmp\mockitoinit\target
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-cli) @ mockitoinit ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\arturo\eclipse_tmp\mockitoinit\target\test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/arturo/eclipse_tmp/mockitoinit/src/test/java/mockitoinit/service/AppInterfaceImplTest.java:[11,17] cannot find symbol
symbol: class AppInterface
location: class mockitoinit.service.AppInterfaceImplTest
[INFO] 1 error
因为无法在src / main / java目录中找到源代码类。
预先感谢, A. Seixo
答案 0 :(得分:0)
据我了解,您的AppInterface
包是mockitoinit.service
。这意味着您必须在import mockitoinit.service.AppInterface
中写上AppInterfaceImplTest
。
UPD:
如您在注释中显示的示例-最好将相同的程序包用于测试和源代码。例如,如果您有源代码包org.kappa.hibernate.job
来测试此页面中的类,则最好将其存储在同一包org.kappa.hibernate.job
中,但存储在test
目录中