junit

Logback LogBack

核能气质少年 提交于 2019-12-21 19:37:06
1.简介   LogBack是一个日志框架,它与Log4j可以说是同出一源,都出自Ceki Gülcü之手。(log4j的原型是早前由Ceki Gülcü贡献给Apache基金会的) 1.1 LogBack,Slf4j,Log4j之间的关系   Slf4j是The Simple Logging Facade for Java的简称,是一个简单日志门面抽象框架,它本身只提供了日志Facade API和一个简单的日志类实现,一般常配合Log4j,LogBack,java.util.logging使用。Slf4j作为应用层的Log接入时,程序可以根据实际应用场景动态调整底层的日志实现框架(Log4j/LogBack/JdkLog...);   LogBack和Log4j都是开源日记工具库,LogBack是Log4j的改良版本,比Log4j拥有更多的特性,同时也带来很大性能提升。详细数据可参照下面地址: Reasons to prefer logback over log4j   LogBack官方建议配合Slf4j使用,这样可以灵活地替换底层日志框架。   (note: 为了优化log4j,以及更大性能的提升,Apache基金会已经着手开发了log4j 2.0, 其中也借鉴和吸收了logback的一些先进特性,目前log4j2还处于beta阶段) 1.2 LogBack的结构  

How to call a method without repeat from other methods in java

坚强是说给别人听的谎言 提交于 2019-12-21 18:32:26
问题 For example, I have thousands of method like: AA() { ... } BB() { ... } CC() { ... } etc ... Now I want to call a method printCurrentMethodName() on the beginning of each method. That means, AA() { printCurrentMethodName(); ... } BB() { printCurrentMethodName(); ... } CC() { printCurrentMethodName(); ... } etc ... Including printCurrentMethodName() on the start of thousands of method is time consuming. Is there any way that I can call printCurrentMethodName() on the beginning of each methods

Grails: How do you unit test a command object with a service injected into it

隐身守侯 提交于 2019-12-21 17:34:15
问题 I am trying to test a Controller that has a Command object with data binding. The Command Object has a Service injected into it. But When I try test the command object the injected service method is never found as it is never "injected" Is there a way to mock a service inside a command object? Test method void testLoginPasswordInvalid() { mockRequest.method = 'POST' mockDomain(User, [new User(login:"freddy", password:"realpassword")]) mockLogging(UserService) // userService mocked MockUtils

When Java class is instance of Serializable

旧时模样 提交于 2019-12-21 14:06:11
问题 I wonder when Java Class is instance of Serializable. As I know class is serializable only if it implements Serializable interface. I'm trying to use junit to generate entity class (from some kind of template) and check if it is serializable. My generated class (which does NOT implement Serializable) looks like: package test; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import javax.annotation.Generated; import javax.persistence.Id; @Entity

How to use persistence.xml and hibernate.cfg.xml in JUnit tests via eclipse?

自闭症网瘾萝莉.ら 提交于 2019-12-21 13:03:37
问题 I have been searching for an answer during quite a long time before coming here and ask this question. My problem is very simple : I cannot run any JUnit test when using the JPA Entity Manager API. It seems that my test is not reading the persistence.xml file. When I call new Configuration().configure().buildSessionFactory() , it works like a charm but an exception is thrown when calling Persistence.createEntityManagerFactory("myapp") is: javax.persistence.PersistenceException: No Persistence

org.h2.jdbc.JdbcSQLException: Schema “MYAPP” not found; SQL statement

梦想与她 提交于 2019-12-21 13:02:57
问题 i am trying to use H2 database with sprint junit test as follows: 1- SpringTestingConfig: @Configuration @ComponentScan(basePackages = "com.myapp.data", excludeFilters = { @Filter(Configuration.class) }) @PropertySource("classpath:/test.properties") @Profile("test") public class SpringTestingConfig { @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUrl("jdbc:h2:mem:test;MODE

Selenium test runs won't save cookies?

狂风中的少年 提交于 2019-12-21 13:01:20
问题 So I'm experimenting with Selenium automation, and I'm trying to write a testcase that logs in, goes to a specific page, inputs data, then presses submit. The issue is that when it runs, it types out the credentials, presses "Submit" the site returns: This site uses HTTP cookies to verify authorization information. Please enable HTTP cookies to continue. But then when I added this line [denoted by //1]: driver.findElement(By.cssSelector("p > input[type=\"submit\"]")).click(); It allowed the

What does @Rule do?

左心房为你撑大大i 提交于 2019-12-21 12:21:30
问题 When trying to make a temporary file for unit tests I came across this answer that mentioned "TemporaryFolder JUnit @Rule" and a link explaining how to use it. Which is like this: @Rule public TemporaryFolder testFolder = new TemporaryFolder(); and then testFolder.newFile("file.txt") My question is what does the @Rule annotation do? Removing the annotation doesn't appear to actually change anything. 回答1: As the documentation of Rule and TemporaryFolder states, it takes care of creating a

Eclipse JUnit4: exclude tests using a name pattern

元气小坏坏 提交于 2019-12-21 12:02:07
问题 Is it possible to specify in the JUnit Run configuration in Eclipse a name pattern (say **/integration/*Test) that should be excluded from the test run when running all tests of a project? Looking at options in the Run/Debug Configuration I presume this question could be reduced to: is it possible exclude certain tests based on junit runner command line parameters. I'm not interested in creating (and maintaining) Test Suites. Another alternative solution (still not interested in that one,

ant junit batchtest from a jar

…衆ロ難τιáo~ 提交于 2019-12-21 10:17:05
问题 I'd like to use ant (post 1.7) to run all tests in classes named *Test.class in a certain jar. Something like the following (although it doesn't actually run any tests): <junit fork="yes" printsummary="on" haltonfailure="on"> <formatter type="xml"/> <batchtest fork="yes" todir="${junit.output.dir}"> <resources> <zipentry zipfile="tests-only.jar" name="**/*Test.class"/> </resources> </batchtest> <classpath refid="testsplus.classpath"/> </junit> What is the correct syntax for the resources