junit

Example HtmlUnit Test Failing

前提是你 提交于 2019-12-19 04:37:08
问题 I am trying to run the sample HtmlUnit test case via Junit. My project is Maven based. Do I need to add ALL the depdencies listen under compile and test to my POM? http://htmlunit.sourceforge.net/dependencies.html Right now I have added the htmlunit dependencies, httpconnections and nekohtml. Sample test: @Test public void homePage() throws Exception { WebClient webClient = new WebClient(BrowserVersion.CHROME_16); final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");

Unit tests coverage using Jacoco for test classes written using Powermock

一曲冷凌霜 提交于 2019-12-19 04:14:48
问题 I am trying to get the code coverage report on the sonarqube dashboard on jenkins. The code coverage report is coming up but showing only 4.6% coverage. On investigating I found out that the test classes written using PowerMocks are getting skipped. On further investigation I found that "JaCoCo doesn't play well with dynamically modified/created classes (this is the way how powermock works). This is a known limitation we can't currently do anything about". Is there any work around for this so

Intent resolved to different process when running Unit Test in Android

笑着哭i 提交于 2019-12-19 04:10:20
问题 I have a small application that uses two activities. Both the activities inherit from MapActivity and display a map (com.google.android.maps). Since the Android Google Map documentation says Only one MapActivity is supported per process. Multiple MapActivities running simultaneously are likely to interfere in unexpected and undesired ways. I modified my manifest to run the two activities in two different processes (I have removed some lines to make it short): <?xml version="1.0" encoding="utf

Java连接Hbase

心已入冬 提交于 2019-12-19 04:08:09
java连接hbase 如何使用java连接hbase? 底层如何操作,我们并不关心;只期望提供以下几个方法 方法1:连接hbase;输入参数:hbase的ip,端口号; 方法2:namespace的crud; 方法3:table的crud; 方法4:记录的crud; 添加jar包 把%hbase_home%\lib\所有的jar包都加进来; 添加工具包:junit和log4j2 添加配置文件 参照:hbase源码的工具类 (hbase-2.2.2-src\hbase-2.2.2\hbaseserver\src\test\java\org\apache\hadoop\hbase\HBaseTestingUtility.java) HbaseBaseTest package com.jinghangzz.hbase.test; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Connection; import org

@WebMvcTest fails with java.lang.IllegalStateException: Failed to load ApplicationContext

本小妞迷上赌 提交于 2019-12-19 03:27:26
问题 I'm having trouble getting my tests annotated with @WebMvcTest to work. I have also configured spring-cloud-config-server and spring-cloud-starter, and all Test classes with this annotation seem to fail. I have the following controller test: Code: @RunWith(SpringRunner.class) @WebMvcTest(controllers = UserController.class) @ActiveProfiles({"dev", "native"}) public class UserControllerTest { @MockBean private UserService userService; @Autowired private MockMvc mockMvc; @Autowired private

EJB testing with TomEE embedded EJBContainer api: java.lang.ClassFormatError exception

一笑奈何 提交于 2019-12-19 03:14:08
问题 I would test my EJB with TomEE embedded EJBContainer. This is my JUnit test case skeleton: package com.xxx.indexer.scheduler.service; import java.util.Properties; import javax.ejb.embeddable.EJBContainer; import javax.naming.NamingException; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import com.xxx.indexer.scheduler.AbstractTest; public class BookingAuditServiceImplTest extends AbstractTest { private static EJBContainer container

How to create unit test with kafka embedded in the spring cloud stream

て烟熏妆下的殇ゞ 提交于 2019-12-19 03:14:08
问题 Sorry for the question being too generic, but someone has some tutorial or guide on how to perform producer and consumer testing with kafka embedded. I've tried several, but there are several versions of dependencies and none actually works =/ I'm using spring cloud stream kafka. 回答1: We generally recommend using the Test Binder in tests but if you want to use an embedded kafka server, it can be done... Add this to your POM... <dependency> <groupId>org.springframework.kafka</groupId>

Can Intellij-IDEA be configured to break on exceptions in JUnit tests that lets the test fail?

别来无恙 提交于 2019-12-19 02:32:09
问题 When I have a JUnit test, I'd like the debugger to stop right at the point where any exception in the tested code is thrown that lets the test fail, in order to inspect what's wrong. Is there a possibility to configure IntelliJ's debugger to do that, and not break on other exceptions? If I set an exception breakpoint on any uncaught exception, this doesn't work since the exception is caught by JUnit. If I try to have the breakpoint break also on caught exceptions with catch class org.junit.,

使用Maven构建多模块项目

孤者浪人 提交于 2019-12-19 00:15:24
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为domain(域模型层)、dao(数据库访问层)、service(业务逻辑层)、web(表现层),这样分层之后,各个层之间的职责会比较明确,后期维护起来也相对比较容易,今天我们就是使用Maven来构建以上的各个层。   项目结构如下:   system-parent     |----pom.xml     |----system-domain         |----pom.xml     |----system-dao         |----pom.xml     |----system-service         |----pom.xml     |----system-web         |----pom.xml 一、创建system-parent项目   创建system-parent,用来给各个子模块继承。   进入命令行,输入以下命令: mvn archetype:create -DgroupId=me.gacl -DartifactId=system-parent -DarchetypeArtifactId=maven-archetype-quickstart

Where should I put interface class for Junit @Category?

China☆狼群 提交于 2019-12-18 23:47:18
问题 I'd like to define project-wide interfaces, to be used in @Category annotations, and configure Maven to exclude their annotated tests when building the whole project. In the application project there's a test I'd like to categorize: @Category(Integration.class) @Test public void testExternalResource() { ... } The setting: I've set up a multi-module maven project: /container (has a pom with <modules> element) /parent (all other modules inherit from its pom. has no source, only pom) /util