junit

Jmock - how to automate & mock out console user input?

十年热恋 提交于 2019-12-25 05:04:25
问题 I have some functionality that I want to mock out being called from main (static: I've read about that too - jmock mocking a static method). i recently read that JMock doesn't support the mocking of static functions. Well, the associated code (that's giving me a problem) must be called from main, and must be in the class with main... Sample source Test code Right now, I want to ensure that my main has a test to make sure that the file exists before it proceeds. Problem is, I have my program

Embedded Jetty Error The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved

孤街浪徒 提交于 2019-12-25 04:25:07
问题 I'm using Embedded Jetty server to run my tests and Maven for build. Following is the code used to start Jetty before tests. System.out.println("Initializing Jetty Server..."); jettyServer = new Server(0); WebAppContext webapp = new WebAppContext("src/main/webapp", "/testApp"); jettyServer.addHandler(webapp); jettyServer.start(); int actualPort = jettyServer.getConnectors()[0].getLocalPort(); String baseUrl = "http://localhost:" + actualPort + "/testApp"; All the tests passes if I run it with

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code

末鹿安然 提交于 2019-12-25 04:07:49
问题 i have a junit test case that runs a code like: if (SecurityUtil.isAuthenticated()) { } and it gives an exception: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration. My Test Class configuration is as follows: @RunWith(SpringJUnit4ClassRunner.class) @TestExecutionListeners({ WebContextTestExecutionListener.class

Junit 4 runner in android test project “Sample Project”

限于喜欢 提交于 2019-12-25 03:59:14
问题 Provide me Android sample test project with only 2-3 java files,by using JUnit 4. I was trying to do this. My main test file. import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ SimpleMathTest.class // add other classes here (comma separated) }) public class TestSuite { } and I made another test file as JUnit 4 that is import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; public

Can I make JUnit more verbose?

梦想的初衷 提交于 2019-12-25 03:57:29
问题 I'd like to have it yell hooray whenever an assert statement succeeds, or at the very least have it display the number of successful assert statements that were encountered. I'm using JUnit4. Any suggestions? 回答1: If you want to see some output for each successful assertion, another simple approach which requires no external dependencies or source code, would be to define your own Assert class which delegates all methods to the standard JUnit Assert class, as well as logging successful

How to debug Solr test cases in Eclipse?

瘦欲@ 提交于 2019-12-25 03:24:11
问题 When I try to run a Solr test case from Eclipse (Right-Click > Run As > JUnit Test), I get the following printed to the Eclipse console: Feb 27, 2012 5:21:06 PM org.apache.solr.SolrTestCaseJ4 deleteCore INFO: ###deleteCore The whole process runs and exits very quickly without running the actual test case. I have tried to set my working directory according to the instructions at http://wiki.apache.org/solr/TestingSolr to no avail. Those instructions refer to a directory that doesn't actually

How to make jUnit class have parameter

时光毁灭记忆、已成空白 提交于 2019-12-25 03:03:07
问题 I have problem with passing a bean class like mvc concept to implement to jUnit class. I don't want change the structure jUnit class, because i have need it. Class DataBean public class DataBean { private String browserName; private String userName; public String getBrowserName() { return browserName; } public void setBrowserName(String browserName) { this.browserName = browserName; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName =

How can I test if this object returns the correct String?

馋奶兔 提交于 2019-12-25 02:53:06
问题 I have a Thing class that holds various Strings and a Collection of Stuff. I have to test whether the Message class can correctly return item as "found" in a MessageTest class. What is the most elegant/efficient way of testing this? What kind of fake object should I create, and how do I test with/against it? public class Thing { public String a; public String b; public String c; public String d; public String e; public Collection<Stuff> collection; } public class Message { private String item

How can I test if this object returns the correct String?

送分小仙女□ 提交于 2019-12-25 02:53:02
问题 I have a Thing class that holds various Strings and a Collection of Stuff. I have to test whether the Message class can correctly return item as "found" in a MessageTest class. What is the most elegant/efficient way of testing this? What kind of fake object should I create, and how do I test with/against it? public class Thing { public String a; public String b; public String c; public String d; public String e; public Collection<Stuff> collection; } public class Message { private String item

How to fix Kafka for JUnit dependencies problem?

若如初见. 提交于 2019-12-25 02:46:25
问题 I want to use Kafka for JUnit, so I added this dependency: <dependency> <groupId>net.mguenther.kafka</groupId> <artifactId>kafka-junit</artifactId> <version>2.1.0</version> <scope>test</scope> </dependency> Locally it works well. But on Jenkins I get an error: java.lang.NoClassDefFound scala/math/Ordering If I add scala-library dependency (version 2.1.12 ), I get: java.lang.NoClassDefFound com.typesafe.scalalogging.Logger$ Also, I have several Apache Beam dependencies with 2.9.0 version. What