준 it 에 대한 첫 번 째 테스트.
junit
。
:0errors 0failures
:^_^
1. +Test java :
2.
3. jar , junit 。
4.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.*,org.*" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/com/el/junit/dao/database-setting.properties</value>
</list>
</property>
</bean>
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />
<tx:annotation-driven/>
<bean id="DataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name = "driverClassName" value="${PETest.database_driver}" />
<property name = "url" value="${PETest.database_url}" />
<property name = "username" value="${PETest.database_username}" />
<property name = "password" value="${PETest.database_password}" />
</bean>
<!-- misc -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name = "dataSource"><ref local ="DataSource"/></property>
<property name = "packagesToScan" value = "com.el.*"/>
<property name = "hibernateProperties">
<props>
<prop key = "hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key = "hibernate.show_sql">true</prop>
<prop key = "hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<bean id = "transactionManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
<!-- <qualifier value="listgrid"/> -->
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="name=get*" read-only="true" />
</tx:attributes>
</tx:advice>
5. </beans>
6. @Before @Test @ After
7. package com.el.junit.dao;
8.
9. import java.util.List;
10.
11. import org.junit.After;
12. import org.junit.Before;
13. import org.junit.Test;
14. import org.springframework.context.ApplicationContext;
15. import org.springframework.context.support.FileSystemXmlApplicationContext;
16.
17. import com.el.dao.InformationDao;
18. /* 1
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath: webRoot/WEB-INF/configs/app-config.xml "})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
19. @Transactional */
20. public class InformationDaoTest {
21.
22. private InformationDao informationDao;
23.
24. @Before
25. public void init() {
26. System.out.println("---------- init ----------");
27. // 2
28. ApplicationContext factory = new FileSystemXmlApplicationContext("webRoot/WEB-INF/configs/app-config.xml");
29. informationDao = factory.getBean(InformationDao.class);
30. }
31.
32. @Test
33. public void test() {
34. System.out.println("---------- test ----------");
35. getAllInfo();
36. }
37.
38. public List<?> getAllInfo(){
39. return this.informationDao.getAllInfo();
40.
41. }
42. @After
43. public void destroy() {
44. System.out.println("---------- End ----------");
45. }
46.
47. }
48.
49.
테스트 할 자바 파일 을 선택 하고 Run as->Junit Test 를 오른쪽 클릭 하면 됩 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.