junit

Jmockit: Can't mock method toString of net.android.Uri class

坚强是说给别人听的谎言 提交于 2019-12-23 05:38:10
问题 IDE: Android Studio 2.2.2 | Jmockit: 2.1 | Java: 1.8.0_102-b14 I tried to mock method toString() of class net.android.Uri. All method on this class could mock OK, but toString() method. @Test public void method(@Mocked final Uri uri) throws Exception { new NonStrictExpectations() { { uri.getHost(); result = "sendViewLog"; uri.getAuthority(); result = "getAuthority"; uri.getEncodedFragment(); result = "getEncodedFragment"; uri.getPort(); result = 8080; uri.toString(); // <------- result =

Unit testing Java application with Mockito/JUnit-Database operations

喜夏-厌秋 提交于 2019-12-23 04:54:23
问题 I am just beginner for implementing JUnit testing. I have a test case as given below. I have tried the when...thenreturn + verify method as well. @RunWith(MockitoJUnitRunner.class) public class CategoryControllerTest { @InjectMocks CategoryController categeoryCntrlr; @Mock private CategoryService catSvc; //private CategoryController catCntrl; @Test public void insertCategoryTest(){ Category cat=new Category(); cat.setStrCatName("Vehicle"); String str = categeoryCntrlr.insertCategory(cat);

PowerMock in Scala: java.lang.NullPointerException when getPackage

怎甘沉沦 提交于 2019-12-23 04:41:49
问题 This code just getPackage and getName of a class (not use any mock techniques yet), but it failed. Anyone see this problem before? Code: import mai.MyScala1 import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner import org.scalatest.junit.JUnitSuite @RunWith(classOf[PowerMockRunner]) class MyTest extends JUnitSuite { @Test def test1() { classOf[MyScala1].getPackage // this one returns null classOf[MyScala1].getPackage.getName // raise java

@BeforeClass and @AfterClass called before and after each test

可紊 提交于 2019-12-23 04:33:30
问题 I have a very simple test class for running espresso tests on Android that looks like this: import android.util.Log; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.ExternalResource; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.io.IOException; @RunWith(JUnit4.class) public class Wtf { private static class TestResources extends

JUnit RunListener is removed on fail()

拥有回忆 提交于 2019-12-23 04:22:28
问题 I am using a RunListener to let test fail when they write to System.out, but when I fail() a unittest, the listener is removed. Is there any way to let tests fail without removing the Listener? For clarification a code example public class OutputListenerTest { @Test public void testPrintIsDicovered() { JUnitCore runner = new JUnitCore(); // the OutputListener calls fail() when something was written runner.addListener(new OutputListener()); Result result = runner.run(TestWithOutput.class); }

Use a variable in PowerShell to pass multiple arguments to an external program

喜欢而已 提交于 2019-12-23 04:05:24
问题 I downloaded the npm package for merge junit reports - https://www.npmjs.com/package/junit-merge. The problem is that I have multiple files to merge and I am trying to use string variable to hold file names to merge. When I write the script myslef like: junit-merge a.xml b.xml c.xml This works, the merged file is being created, but when I do it like $command = "a.xml b.xml c.xml" junit-merge $command This does not work. The error is Error: File not found Has anyone faced similar issues? 回答1:

Junit : Exception while creating BOFactory instance

非 Y 不嫁゛ 提交于 2019-12-23 03:14:25
问题 I am trying to setup JUnit framework on IID8.5. But when I am trying to run simple JUnit testcase I am receiving runtime error. ( java.lang.NoClassDefFoundError: org.eclipse.core.runtime.RegistryFactory ) I am using JUnit4.Please find attached image showing project structure **Code in BOUtils.java ** package com.wf.utils; import com.ibm.websphere.bo.BOFactory; import com.ibm.websphere.sca.ServiceManager; import com.ibm.websphere.sca.Service.*; public class BOUtils { /** * @param args */

spring boot单元测试

丶灬走出姿态 提交于 2019-12-23 03:13:29
JUnit使用 JUnit主要用于白盒测试和回归测试。 检测JUnit依赖 如果是Spring Boot项目默认已经加入了JUnit框架支持,可在pom.xml中查看: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> 如果Maven项目中没有添加JUnit依赖,可参照如上代码,手动添加。 基础使用 简单的测试代码如下: @RunWith(SpringRunner.class) @SpringBootTest public class SimpleTest { @Test public void doTest() { int num = new Integer(1); Assert.assertEquals(num, 1); } } 注解说明 注解列表 @RunWith:标识为JUnit的运行环境; @SpringBootTest:获取启动类、加载配置,确定装载Spring Boot; @Test:声明需要测试的方法; @BeforeClass:针对所有测试,只执行一次,且必须为static void; @AfterClass:针对所有测试,只执行一次

JUnit: Run one test with different configurations

情到浓时终转凉″ 提交于 2019-12-23 02:48:27
问题 I have 2 test methods, and i need to run them with different configurations myTest() { ..... ..... } @Test myTest_c1() { setConf1(); myTest(); } @Test myTest_c2() { setConf2(); myTest(); } //------------------ nextTest() { ..... ..... } @Test nextTest_c1() { setConf1(); nextTest(); } @Test nextTest_c2() { setConf2(); nextTest(); } I cannot run them both from one config (as in code below) because i need separate methods for tosca execution. @Test tests_c1() { setConf1(); myTest() nextTest(); }

Persist/commit not working in test environment with Spring JPA JUnit

≯℡__Kan透↙ 提交于 2019-12-22 19:24:20
问题 I'm trying to setup a basic JPA insert test. But nothing is saved in the DB. DB is Postgresql. Hibernate is used as Persistence provider. Many thanks in advance. @Entity public class Currency { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected Integer id; @Column private String code; @Column private String name; ... } The CRUD class : @Repository @Scope(BeanDefinition.SCOPE_PROTOTYPE) @Transactional(propagation = Propagation.REQUIRED) public class CRUDServiceBean implements