이유 :
첫째, pom.xml 파일에 종속성을 추가
같은 스프링 컨텍스트의 버전 번호에 버전 번호를이 종속성을 추가하고주의
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
나중에 4.12 또는, 또는 잘못된해야합니다 곳의 JUnit 의존성,주의를 기울 추가
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
둘째, 테스트 클래스를 수정
1 위, 여기서 CLASSPATH 추가 주목 ContextConfiguration, 주석 형으로 첨가 하였다 :
2 클래스는 자동 주입 IAccountService 개체
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:bean.xml")
public class AccountServiceTest {
@Autowired
private IAccountService as;
@Test
public void testFindAll(){
List<Account> accounts= as.findAllAccount();
for (Account account:accounts){
System.out.println(account);
}
}
@Test
public void testFindById(){
Account account = as.findAccountById(1);
System.out.println(account);
}
@Test
public void testSaveAccount(){
Account account = new Account();
account.setName("小新");
account.setMoney(4000d);
as.saveAccount(account);
System.out.println("插入后如下:");
testFindAll();
}
@Test
public void testUpdateAccount(){
Account account = as.findAccountById(5);
account.setMoney(5000d);
as.updateAccount(account);
System.out.println("更新后如下:");
testFindAll();
}
@Test
public void testDeleteAccount(){
as.deleteAccount(5);
System.out.println("删除后如下:");
testFindAll();
}
}
기록은 구덩이를 강화
전에 또한, 메이븐 종속성을 추가하고 빨간색보고되지 찾았지만, 사실에 추가하지, 즉 외부 라이브러리없이 해당 패키지를 마우스 오른쪽 프로젝트에서 maven-> 다시 가져 오기에는 반응 솔루션으로 다음과됩니다 없다 :
1. 오른쪽 프로젝트 -> 개방 모듈 설정 -> 왼쪽 목록 Libraries-> 잘못된 패키지를 삭제 (또는 단순히 모든 Ctrl + A 삭제) 다음 다시 가져 오기
2, 파일 -> 설정 -> 빌드, 실행, Deployment-> 빌드 도구 -> 메이븐을, 업데이트 스냅 샷을 항상 확인
하지 실용적 3, 온라인 참조 : IMI 삭제 파일을 프로젝트에 다시 시작 아이디어