testing

JUnitCore Stopping

大兔子大兔子 提交于 2019-12-23 22:19:28
问题 I want to stop/destroy a running JUnitCore, which is started with JUnitCore.run(Request.aClass(ClassToRun)); Like pleaseStop() on the RunNotifier. Any ideas? http://junit.sourceforge.net/javadoc/org/junit/runner/package-summary.html 回答1: Option 1: the best option is to write your own Runner implementation, inherited from org.junit.runners.BlockJUnit4ClassRunner and declare it in your execution context, for instance as Main Class of a raw Java command line. Get inspired of JUnit source code

Groovy Singleton and testing issue (with Spock)

倖福魔咒の 提交于 2019-12-23 22:10:23
问题 There's a discusson here about testing and singletons... but that is about Java patterns. My question is specifically about the Groovy @Singleton (annotation) way of implementing this pattern. This seems like another bit of Groovy Goodness. But I have a bit of a problem when testing (with Spock) using a class which has this annotation. If any of the state of this instance changes during a test (from the pristine, just-constructed state), as far as my experiments indicate this will then carry

iOS In App Purchase sandbox testing says I have the wrong password

折月煮酒 提交于 2019-12-23 21:41:06
问题 I created a Sandbox Tester account in itunesconnect and verified the email address through the email that I registered on the web. After verification, I tried to purchase something in my app with the Sandbox Account and I was alerted to change my password; so I did. Then I tried to purchase something in my app again with the new password and it says that the Apple ID / password is not recognized. Am I doing something incorrect in this process? 回答1: What you do is correct. The sandbox service

TestNG Using @Factory and @DataProvider

安稳与你 提交于 2019-12-23 21:33:07
问题 I'm very new using TestNG and Java programming in general and I have a question in regards to using @Factory and @DataProvider together. I want to test submitting a web form multiple times with different input data every time. I have the following code: public class SolicitudEmpleo extends LaunchBrowser { private String campoDni; private String firstName; private String lastName; @Factory (dataProvider="dataProviderMethod") public SolicitudEmpleo(String campoDni, String firstName, String

How to use output buffering inside PHPUnit test?

烈酒焚心 提交于 2019-12-23 21:15:05
问题 I'm using PHPUnit to test a function which downloads a file. I want to test that the correct file is downloaded and so my idea was to check the output of the function. I'm trying to use output buffering: ob_start(); $viewer->downloadById($fileId); $output = ob_get_flush(); $this->assertEquals($expectedFileContents,$output); The test passes/fails when it should, which is good. My issue is that the contents of the output buffer is also printed to the console. How do I hide this? 回答1: Use ob_get

How to mock Kotlin Object in android?

我怕爱的太早我们不能终老 提交于 2019-12-23 21:05:52
问题 I have an object in kotlin that controls the current user's session information. I want to mock the sign in method which has a call back. While testing, I need to mock this method in the SessionController object. object SessionController { ... fun signIn(username: String, password: String, signInCallBack: SignInCallBack) { sessionApi.attemptSignIn(username,password,object: SignInCallBack{ override fun onSignInComplete() { signInCallBack.onSignInComplete() } override fun onErrorOccurred

Test if an exception is caught with Junit

半腔热情 提交于 2019-12-23 20:22:49
问题 I'll begin with a code example; I have to test a function, which handles data-packets. In this function, the data-packet is opened and when it doesn't contain all expected data, an InvalidParameterExeption is thrown which is logged. public void handleData(dataPacket) { try { analyseData(dataPacket); } catch (InvalidParameterException e) { e.printStackTrace() } } So, if everything goes well, my exception is printed in my terminal. But how can I test this? I can't use this: (because the

How to unit test Java code that dynamically renders html and css?

十年热恋 提交于 2019-12-23 20:11:05
问题 I have a a Java class that gets a form definition from database then renders html, javascript and css according to the form definition, its using a lot of "appendable.append(...).append(...)" to build the html snippets, which is error prone. Jsp and common templating framework(eg.FreeMarker) is not an option here as the javascript, css, html elements are all dynamic(depending on the form definition). and for some reasons, GWT is not an option either. A straight forward way of unit testing

How can I add a Maven exec task to execute on `mvn test`

≡放荡痞女 提交于 2019-12-23 20:03:50
问题 I have the following exec task in my pom: <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>${project.basedir}/src/test/javascript/EnvJasmine/bin/run_all_tests.sh</executable> </configuration> </plugin> </plugins> This works great when I run mvn exec:exec But I also want it to run when I execute mvn test Can

What am I doing wrong with this rspec helper test?

拥有回忆 提交于 2019-12-23 19:49:38
问题 All I'm trying to do is spec how a one line helper method for a view should behave, but I'm not sure what kind of mock object, (if any) I should be creating if I'm working in Rails. Here's the code for events_helper.rb: module EventsHelper def filter_check_button_path params[:filter].blank? ? '/images/buttons/bt_search_for_events.gif' : '/images/buttons/bt_refine_this_search.gif' end end And here's my spec code, in events_helper_spec.rb: require File.expand_path(File.dirname(__FILE__) + '/..