junit

VerifyError while JUnit test involving Document and DocumentBuilder

泪湿孤枕 提交于 2020-01-16 12:35:25
问题 MyClass DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; db = dbf.newDocumentBuilder(); //java.lang.verifyError here Document doc = db.newDocument(); MyClassTest documentBuilderFactory = PowerMockito.mock(DocumentBuilderFactory.class); PowerMockito.mockStatic(DocumentBuilderFactory.class); PowerMockito.when(DocumentBuilderFactory.newInstance()).thenReturn(documentBuilderFactory); document = PowerMockito.mock(Document.class); //documentBuilder =

VerifyError while JUnit test involving Document and DocumentBuilder

左心房为你撑大大i 提交于 2020-01-16 12:35:08
问题 MyClass DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; db = dbf.newDocumentBuilder(); //java.lang.verifyError here Document doc = db.newDocument(); MyClassTest documentBuilderFactory = PowerMockito.mock(DocumentBuilderFactory.class); PowerMockito.mockStatic(DocumentBuilderFactory.class); PowerMockito.when(DocumentBuilderFactory.newInstance()).thenReturn(documentBuilderFactory); document = PowerMockito.mock(Document.class); //documentBuilder =

Why do JUnit 5 Suite annotations @SelectClasses and @IncludeClassNamePatterns fail to find tests that don't end in “Tests” or “Test”?

丶灬走出姿态 提交于 2020-01-16 09:09:34
问题 While upgrading to JUnit 5 (version 5.5.2), I have made a strange discovery with the suite functionality: my suites can find and run tests that end with the word "Test" but fail to find tests that don't end in "Test" (in my case, they end in "Base"). In JUnit 4, we used the @Suite.SuiteClasses() annotation to find these tests, but the JUnit 5 @SelectClasses annotation seems to miss these test classes entirely. Even using @IncludeClassNamePatterns({"^Com.*Base.*?$"}) fails to detect the tests,

EvoSuite - Parameters For Getting Most Code Coverage

China☆狼群 提交于 2020-01-16 03:53:09
问题 I'm generating unit tests with EvoSuite and would like to get as close to 100% code coverage from the resulting unit tests as possible. What are the best command line options/parameters to set to accomplish this? 回答1: EvoSuite comes with its parameters already tuned. if you want to improve coverage further, you d need to increase the allotted time for test generation (eg by using -Dsearch_budget parameter), although that cannot guarantee 100% coverage. For more info, see http://www.evosuite

Android Studio: Could not download junit.jar (junit:junit:4.12)

随声附和 提交于 2020-01-16 03:00:06
下载了Android Studio 3.1.4,新建一个项目,选择Activity,结果gradle提示 Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not download junit.jar (junit:junit:4.12) Open File Show Details Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not download junit.jar (junit:junit:4.12) Open File Show Details Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not download junit.jar (junit:junit:4.12) Open File Show Details 解决方法 1、下载junit 点击 https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.jar ,放在...\Android Studio\gradle\gradle

NoSuchBeanDefinitionException using @Autowired in spring test

試著忘記壹切 提交于 2020-01-16 02:51:27
问题 I have spring-mvc-security project and I am trying create junit test from JavaConfig for one of the controllers, but when i use @Autowired i get exception: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.secure.service.face.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true

JUnit initialization of static fields

帅比萌擦擦* 提交于 2020-01-15 11:22:53
问题 I'm using JUnit for unit testing. Let's say I want to test class B (methods of class B ). Let's say we have another class A which is the main class (contains main method) and has some protected static fields. Now, it is the case that class B uses some of these static fields of class A . So if I'm testing class B these static fields of class A does not exist. How can I test class B without executing the program (executing class A )? Edit: I have to clarify it. Let's assume we have the

Running Eclipse Junit plug-in tests using JUnit5

柔情痞子 提交于 2020-01-15 11:11:37
问题 When I run a simple example like the eclipse plug-in test, I get the following error: java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test], {ExactMatcher:fDisplayName=test(ru.cft.platform.deployment.ui.plugin.reverse.qqq)], {LeadingIdentifierMatcher:fClassName=ru.cft.platform.deployment.ui.plugin.reverse.qqq,fLeadingIdentifier=test]] from org.junit.internal.requests.ClassRequest@310850ef at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) at

@WebMvcTest does not find buildProperties

六眼飞鱼酱① 提交于 2020-01-15 10:06:59
问题 I have working JUnit tests for my MVC controllers. Now I wanted to display the build number in the footer of every page, so I added the following div in my thymeleaf templates: <div class="versionInfo">Version <span th:text="${@buildProperties.getVersion()}"></span></div> Now the test fail with: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'buildProperties' available I tried to add it as a mock to no avail: @MockBean private BuildProperties

How to test that a method should take more than X seconds to finish(with JUnit)?

点点圈 提交于 2020-01-15 08:11:13
问题 Basically I need the opposite behaviour of the @Test(timeout=X) annotation. The problem I want to solve is to detect in some way that the method never ends (as a right behaviour). I am assuming that if the method didn't stop after X seconds, I am sure "it will never end". Thanks! 回答1: You could try this: @Test public void methodDoesNotReturnFor5Seconds() throws Exception { Thread t = new Thread(new Runnable() { public void run() { methodUnderTest(); } }); t.start(); t.join(5000); assertTrue(t