junit

How to test spring configuration classes?

只谈情不闲聊 提交于 2019-12-20 18:35:32
问题 I have a spring application whith configuration classes where instance the beans. Aplication class: @Configuration @EnableAspectJAutoProxy @EnableSpringDataWebSupport @EnableTransactionManagement @ComponentScan(basePackageClasses = Application.class) @PropertySource(value = {"classpath:foo.properties"}) @EnableJpaRepositories(basePackageClasses = Application.class) @EnableJpaAuditing public class Application { @Inject private Environment env; @Bean JndiTemplate jndiTemplate() { return new

How to use Mockito to show all invocations on a mock

半腔热情 提交于 2019-12-20 17:36:30
问题 I have a unit test that is failing and I'm unsure why. I want to be able to see all invocations on the mock that occur in the System Under Test. This is not the behavior that I want for all tests always, simply for a test that I need to quickly tweak to be able to figure out what's wrong. However, it seems kind of like a hack. Is it possible to do this natively in Mockito, without having to use Thread.currentThread().getStackTrace() ? This is not preferred, because the stack trace includes

How to handle ordering of @Rule's when they are dependent on each other

不羁岁月 提交于 2019-12-20 16:17:26
问题 I use embedded servers that run inside Junit test cases. Sometimes these servers require a working directory (for example the Apache Directory server). The new @Rule in Junit 4.7 can handle these cases. The TemporaryFolder-Rule can create a temporary directory. A custom ExternalResource-Rule can be created for server. But how do I handle if I want to pass the result from one rule into another: import static org.junit.Assert.assertEquals; import java.io.*; import org.junit.*; import org.junit

错误java.lang.OutOfMemoryError:超出了GC开销限制

≡放荡痞女 提交于 2019-12-20 15:22:34
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我执行JUnit测试时收到以下错误消息: java.lang.OutOfMemoryError: GC overhead limit exceeded 我知道什么是 OutOfMemoryError ,但是GC开销限制是什么意思? 我该如何解决? #1楼 该消息表示由于某种原因,垃圾收集器占用了过多的时间(默认情况下为该进程所有CPU时间的98%),并且每次运行时恢复的内存很少(默认为堆的2%)。 这实际上意味着您的程序停止任何进展,并且一直在忙于仅运行垃圾回收。 为了防止您的应用程序浪费CPU时间而不做任何事情,JVM抛出此 Error 以便您有机会诊断问题。 我见过这种情况的罕见情况是,某些代码在一个已经非常受内存限制的环境中创建了大量的临时对象和大量的弱引用对象。 请查看 本文 以了解详细信息(特别是 本部分 )。 #2楼 当在垃圾回收上花费太多时间而返回的次数太少时,GC就会抛出此异常。 GC上花费了98%的CPU时间,并且不到2%的堆被恢复。 此功能旨在防止应用程序长时间运行,而由于堆太小而几乎没有进展,甚至没有进展。 您可以使用命令行选项 -XX:-UseGCOverheadLimit 将其关闭 -XX:-UseGCOverheadLimit 更多信息 在这里 编辑:看起来有人可以比我更快地输入:)

How to run JUnit tests for Java from the command line [duplicate]

空扰寡人 提交于 2019-12-20 14:44:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to run Junit testcases from command line? I've run my JUnit tests using maven before. Now I'm packaging all my source code into a JAR file, and want to run it using a java command. How can I do that? Note that there is no main class in my code. 回答1: You need to make sure the classpath contains Your JAR The JUnit JAR You can set the class path by using the -cp flag to the java command. Then you can use junit

How to list the slowest JUnit tests in a multi-module Maven build

╄→尐↘猪︶ㄣ 提交于 2019-12-20 14:21:05
问题 How can I list the slowest JUnit tests in a multi-module Maven build? This should be accross all modules. A Hudson/Jenkins solution could also do. 回答1: Disclaimer: I truly apologize for my bash solution, although it works and fits in one line :-). If you are impatient, go to the bottom. First we need to find all TEST-*.xml files produced by maven-surefire-plugin . Run this after mvn test in the root directory of your project to discover test results in all submodules: $ find . -iname "TEST-*

How to list the slowest JUnit tests in a multi-module Maven build

与世无争的帅哥 提交于 2019-12-20 14:20:09
问题 How can I list the slowest JUnit tests in a multi-module Maven build? This should be accross all modules. A Hudson/Jenkins solution could also do. 回答1: Disclaimer: I truly apologize for my bash solution, although it works and fits in one line :-). If you are impatient, go to the bottom. First we need to find all TEST-*.xml files produced by maven-surefire-plugin . Run this after mvn test in the root directory of your project to discover test results in all submodules: $ find . -iname "TEST-*

Using PowerMock or How much do you let your tests affect your design? [closed]

若如初见. 提交于 2019-12-20 11:56:18
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I've been a fan of EasyMock for many years now, and thanks to SO I came across references to PowerMock and it's ability to mock Constructors and static methods, both of which cause problems when retrofitting tests to a legacy codebase. Obviously one of the huge benefits of

Testing drag-and-drop files onto application

强颜欢笑 提交于 2019-12-20 11:36:54
问题 I am looking for a method to perform a drag-and-drop of a file/multiple files onto my application from a unit test. For example selecting some files in Windows Explorer, drag them and drop them on my application. I am capable of testing drag-and-drop behavior between two components in my application (see below - feel free to indicate if you know a better way), but I have no idea how to do the same when the data has to come from outside my application. I thought about using the debugger to

Why assertEquals and assertSame in junit return the same result for two instances same class?

拟墨画扇 提交于 2019-12-20 11:36:22
问题 According to documentation assertEquals() Asserts that two objects are equal. assertSame() Asserts that two objects refer to the same object. So I am expecting that if I have a class like below class SomeClass {} then SomeClass someClass1= new SomeClass(); SomeClass someClass2= new SomeClass(); assertSame(someClass1,someClass2); // fail assertEquals(someClass1,someClass2); // fail the assertEquals should pass and assertSame should fail, as the value of both classes are equal but they have