junit4

@Rollback(false) not working on @Before using SpringJUnit4ClassRunner

China☆狼群 提交于 2019-12-10 15:04:25
问题 In a JUnit test in my Spring application, I'd like to insert a lot of data in a setup method, and then use it to test against. However, whatever is done in the @Before method appears to be rolled back after each test, even if I annotate the method with @Rollback(false) Here's a simplified version of what I'm trying to do: public class TestClass { @Autowired MyService service; @Before public void setup() { if(service.getById(1) == null) { Thing thing = new Thing(); thing.setId(1); service

How can I fail a JUnit Test from within a test rule

不打扰是莪最后的温柔 提交于 2019-12-10 14:20:51
问题 I have some async code that may throw an exception that JUnit misses (so the test passes). I've created a TestRule to collect those exceptions into a list. After any test has finished, an assertion runs over the list and fails the test if the exception list is non-empty. Instead of failing after the test finishes, I would like to fail the test immediately when the exception occurs. Is this possible to do this with a TestRule ? My TestRule /** * Coroutines can throw exceptions that can go

PowerMock will not work with JAXB Unmarshal

a 夏天 提交于 2019-12-10 13:15:29
问题 I'm creating a test case wherein, I input xml and unmarshal it to procced with processing. I'm trying to use PowerMock and I keep getting javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.xxxxxxx.org/xxxxx/xx/xx", local:"Element"). Expected elements are <{}NotifRQ>,<{http://www.xxxxxxx.org/xxxxx/xx/xx}NotifRS>,etc at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:659) at com.sun.xml.internal.bind.v2.runtime

espresso onView inconsistent performance

霸气de小男生 提交于 2019-12-10 12:51:48
问题 I am using Junit4 and Espresso for my tests. I am facing a weird issue with espresso tests - when I call onView sometimes everything is executed like it is supposed to, but sometimes my test freezes and after 60 seconds I get something like this "android.support.test.espresso.AppNotIdleException: Looped for 63 iterations over 60 SECONDS. The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED" For example : onView(withId(R.id.zone_button_continue)).perform(click()); onView(withId(R.id

Selenium Scripts on the command line

那年仲夏 提交于 2019-12-10 11:40:59
问题 Is there any way to run selenium webdriver tests scripts from the command line that have been written using Java and JUnit through Eclipse IDE? I've been trying to use Ant or Maven but I can't get it working. Can someone please offer some advice about where to go with this? 回答1: The following steps will help you run selenium scripts from the command prompt without the help of eclipse. Set the CLASSPATH for all the supporting files. Right-Click on MyComputer-->Proprties-->Advanced System

Alternate way to run Cucumber without JUnit?

亡梦爱人 提交于 2019-12-10 11:38:22
问题 Is there any alternate way to run the cucumber without Junit. Is that any possible way to run cucumber as a Java application.. like if I create a main() method and control all step definitions over there? Any help will be awesome 回答1: The answer is out of date. The cucumber docs have this to say, "Running Cucumber There are several ways to run scenarios with Cucumber-JVM: JUnit Runner CLI Runner Android Runner Third party runners " 回答2: Cucumber JVM can be invoked from command line. So the

How to add arguments to junit test triggered from command line?

青春壹個敷衍的年華 提交于 2019-12-10 10:34:29
问题 This thread here shows how to test a JAR with JUnit tests. However, I want to submit additional properties from the command line (because I want to test my main method). How to run JUnit tests for Java from the command line e.g. java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore [MyTest] [PortNumber] [fileToRead] Anything like that possible? 回答1: You could use system properties java -cp ... YOUR_TEST -DportNumber=1234 Then in code, you can retrieve it with System.getProperty(

Gradle Android unit tests that depend on multiple module

梦想的初衷 提交于 2019-12-10 10:03:03
问题 I am working on a project which has multiple modules. We are writing junit test cases for application and we are using below exception. Test running started java.lang.RuntimeException: java.lang.ClassNotFoundException: Below is the project dependency  Library project 1  Library project 2 – depends on Library project 1  Library project 3– depends on Library project 1  Main launch project– depends on Library project 2 and Library project 3 From Library project 1 we are accessing the classes

junit4备忘录

时间秒杀一切 提交于 2019-12-10 09:47:16
简介 JUnit是一个Java语言的单元测试框架。它由Kent Beck和Erich Gamma建立,逐渐成为源于Kent Beck的sUnit的xUnit家族中最为成功的一个。 测试用例不是用来证明你(的逻辑)是对的,而是用来证明你(的断言)没有错。 junit3与junit4区别 在JUnit3中需要继承TestCase类,JUnit4不需要继承任何类; 在JUnit3中需要覆盖TestCase中的setUp和tearDown方法,其中setUp方法会在测试执行前被调用以完成初始化工作,而tearDown方法则在结束测试结果时被调用,用于释放测试使用中的资源,而在JUnit4中,只需要在方法前加上@Before,@After ; 在JUnit3中对某个方法进行测试时,测试方法的命令是固定的,例如对addBook这个方法进行测试,需要编写名字为tetAddBook的测试方法,而在JUnit4中没有方法命令的约束,在方法的前面加上 @Test ,这就代表这个方法是测试用例中的测试方法; 新的断言assertThat; @BeforeClass 和 @AfterClass 。在JUnit3,如果所有的test case仅调用一次setUp()和tearDown()需要使用TestSetup类; 测试异常处理@Test(expected = DataFormatException

Selenium web driver not able to close firefox instance if a Test cases is failed

谁说我不能喝 提交于 2019-12-10 07:47:07
问题 i folks, i am using junit with selenium web driver 2.28. the problem is if i run a successful test case the web drives is able to close the firefox instance, but when a test case fails the selenium web driver is not able to close the firefox. i am using FF 15.0.1 with selenium-server-standalone-2.28.0.jar. please respond thanks Sahil private void startWebdriver() throws UIException{ //2) Prevent re-use. if(UIHandlerWD.this.profile == null) throw new UIException( UIException.Code.UI,