Skip to content

Instantly share code, notes, and snippets.

@superalsrk
Last active December 21, 2015 08:59
Show Gist options
  • Save superalsrk/6282309 to your computer and use it in GitHub Desktop.
Save superalsrk/6282309 to your computer and use it in GitHub Desktop.
spring-test related gists
package com.farmol.model.core.service;
import static org.junit.Assert.fail;
import javax.annotation.Resource;
/**
* notice that you have to include Logger of log4j package ,not other package
*/
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.farmol.model.core.entity.Category;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/spring/applicationContext.xml")
/**
* TestClass also can extends from AbstractJUnit4SpringContextTests
* @author SageLui
*/
public class CategoryServiceTest extends AbstractTransactionalJUnit4SpringContextTests {
@Resource
private CategoryService categoryService;
private static Logger logx = Logger.getLogger(CategoryServiceTest.class);
private static Log mylog = LogFactory.getLog("warnLogger");
@Before
public void setUp() throws Exception {
}
@Ignore@Rollback(false)
public void testSave() {
Category category = new Category();
category.setCategoryName("鸡");
category.setCreatedTime(new java.util.Date());
categoryService.save(category);
logger.warn(category.getCategoryName());
}
@Test@Rollback(false)
public void testUpdate() {
logx.warn("test1");
mylog.error("test2");
}
@Ignore
public void testDelete() {
fail("Not yet implemented");
}
@Ignore
public void testQueryById() {
fail("Not yet implemented");
}
}
log4j.rootLogger=WARN,METRICS
log4j.logger.warnLogger=WARN,METRICS
log4j.additivity.warnLogger=false
log4j.appender.METRICS=org.apache.log4j.ConsoleAppender
log4j.appender.METRICS.layout=org.apache.log4j.PatternLayout
log4j.appender.METRICS.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.logger.org.springframework=WARN, org.springframework, METRICS
log4j.appender.org.springframework=org.apache.log4j.FileAppender
log4j.appender.org.springframework.File=d\:spring.log
log4j.appender.org.springframework.Encoding=utf8
log4j.appender.org.springframework.layout=org.apache.log4j.PatternLayout
log4j.appender.org.springframework.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n
# Control logging for other open source packages
log4j.logger.com.opensymphony.oscache=ERROR
log4j.logger.net.sf.navigator=ERROR
log4j.logger.net.sf.acegisecurity=WARN
log4j.logger.net.sf.acegisecurity.intercept.event.LoggerListener=WARN
log4j.logger.org.apache.commons=ERROR
log4j.logger.org.apache.struts=WARN
log4j.logger.org.displaytag=ERROR
log4j.logger.com.ibatis.db=WARN
log4j.logger.org.apache.velocity=WARN
# Don't show debug logs for WebTest
log4j.logger.com.canoo.webtest=WARN
# All hibernate log output of "info" level or higher goes to stdout.
# For more verbose logging, change the "info" to "debug" on the last line.
log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN
log4j.logger.org.hibernate=WARN
# Changing the log level to DEBUG will result in Hibernate generated
# SQL to be logged.
log4j.logger.org.hibernate.SQL=ERROR
# Changing the log level to DEBUG will result in the PreparedStatement
# bound variable values to be logged.
log4j.logger.org.hibernate.type=ERROR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment