junit

Can't suppress DriverManager's static initializer block

僤鯓⒐⒋嵵緔 提交于 2019-12-22 16:40:22
问题 I have a unit test that attempts to create a SQLException to simulate a database error. In SQLException 's constructor, there is a call to DriverManager , which has a static initialization block. I figured that I could suppress the static block with this type of setup: @RunWith(PowerMockRunner.class) @SuppressStaticInitializationFor({"java.sql.DriverManager"}) public class StaticTest { @Test public void testStaticSuppress() throws Exception { SQLException ex = new SQLException(); expect(...)

Junit fails on french string assertion

霸气de小男生 提交于 2019-12-22 14:03:55
问题 I have a unit test that works well on most machine but one ubuntu box seems to not be able to compare special characters "?". The character itself should be â. On my machine the eclipse console displays it normally which encoding should we be playing with to ensure that this works. The extracted text was wrong expected:<...tons. Il jette le bl[?me sur .... but was:<...tons. Il jette le bl[?me sur ..... The test is ran within Eclipse Juno using Maven 2 using java 1.7 Does anyone have an idea..

JUnit: Can (should) this be done?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 13:40:20
问题 I'm trying to write some UI-Tests for a web app, but there are a couple of complications that I hope you could help me resolve. First of all the app has two modes. One of the modes is 'training' and another is 'live'. In live mode the data is taken straight from our database and any changes made by my tests are reflected in the database, before running each test in 'live' I need to generate the test data as it's different every time (I already have that logic in place). In training mode all

Jmeter: Using jmeter Junit Request with variables

五迷三道 提交于 2019-12-22 12:44:09
问题 As I said in the question, is it possible to pass jmeter variables (passed through -J) into a JUnit Request in order that it can be used internally to the junit test? It sounds feasible as the Apache Junit Request docs indicate that: ... JMeter currently runs the test methods directly, rather than leaving it to JUnit. ... This would indicate that jmeter could control passing parameters but I've found no supporting documentation and there's no obvious mechanism through the JUnit Request

arquillian UnsupportedOperationException when use InSequence annotation

妖精的绣舞 提交于 2019-12-22 12:32:38
问题 I get the error when I add @InSequence annotation to my tests: java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableList$1.set(Collections.java:1412) at java.util.Collections.sort(Collections.java:234) at org.jboss.arquillian.junit.Arquillian.getChildren(Arquillian.java:71) at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:426) at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:351) at org.junit.runners.Suite.describeChild(Suite

PowerMock - Mocking static system class throws IllegalStateException

百般思念 提交于 2019-12-22 12:26:18
问题 I have the following code public class A{ public void createFile() { File tempXmlFile = null; String extension = ".xml"; String name = "someName"; try { tempXmlFile = File.createTempFile(name, extension); if (tempXmlFile.exists()) { tempXmlFile.delete(); } } catch (IOException e) { System.out.println(e.getStackTrace()); } } } @RunWith(PowerMockRunner.class) @PrepareForTest(A.class) public class testA extends TestCase{ private A classUnderTest; @Override @Before public void setUp() {

Code generating JUnit based on Abstract Syntax tree walk

馋奶兔 提交于 2019-12-22 12:25:08
问题 Assuming I have the following class and method: package generation; class HelloWorld { public boolean isEven(int val) { if ( (val % 2) == 0) return true; else return false; } } Assume I want to generated the following JUnit test: package generation; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; public class HelloWorldTest { @Test public void testIsEven() { HelloWorld h = new HelloWorld(); assertTrue(h.isEven(2)); assertFalse(h

JUnit Plug-in Test Ignores Target Platform in Eclipse Neon

老子叫甜甜 提交于 2019-12-22 12:22:27
问题 I have some problems getting JUnit plug-in tests to work using Eclipse Neon M7 and I'd really like input from anybody out there who uses tests (there has to be somebody , right?). Whenever I start a test that works in Eclipse Luna (but didn't in Mars, which I assumed was a bug) and continues to work using Tycho I get the following exception: !SESSION 2016-05-11 10:25:41.456 ----------------------------------------------- eclipse.buildId=unknown java.version=1.8.0_73 java.vendor=Oracle

IntelliJ + JUnit 5 (Jupiter)

你。 提交于 2019-12-22 10:59:47
问题 My build.gradle has: testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0' Using the standard example from http://junit.org/junit5/docs/current/user-guide/ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class FirstJUnit5Tests { @Test void myFirstTest() { assertEquals(2, 1 + 1); } } When I try to run as a JUnit test in IntelliJ 2017.2.3, I get: objc[32347]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8

Spring MVC: How to unit test Model's attribute from a controller method that returns String?

心不动则不痛 提交于 2019-12-22 10:58:58
问题 For example, package com.spring.app; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * Handles requests for the application home page. */ @Controller public class HomeController { @RequestMapping(value = "/", method = RequestMethod.GET) public String home(final Model model) { model.addAttribute("msg", "SUCCESS"); return "hello"