junit

How can I use jUnit to test a class that uses a singleton?

a 夏天 提交于 2019-12-25 02:41:02
问题 I am developing a simulator for a machine. It reads a file in, stores it in a string (as a binary number) to an array that is supposed to simulate the memory of a computer. Then it gets passed to an interpreter that takes gets the first element of the array, and based on the first 4 characters it gets sent to another class. An example of one of those classes is below: public class Add { private String cell; Add() { cell = null; } /** * Method that performs the operation add. */ public void

JUnit test fails even if the expected result is correct

╄→尐↘猪︶ㄣ 提交于 2019-12-25 02:40:09
问题 I have tried to run the JUnit test, but it keeps failing - even if the code is supposed to pass the test. Any ideas why? I have put the function, the conversion factor and the test This is the test: private static MathContext mc = new MathContext( 12, RoundingMode.HALF_EVEN ); public static final BigDecimal testValue = new BigDecimal( 123456.1234567 ); @Test public final void testconvertFathomToMetersDM3() { BigDecimal expectedResult = unitConverter.convertFathomToMetersDM3(testValue);

How to mock public void method using jmockit?

℡╲_俬逩灬. 提交于 2019-12-25 02:29:31
问题 I am trying to write some junit test for my Spring MVC controller and so far I am able to do it successfully. I am using Spring Mock along with jmockit as well. Below is my method in the DataController controller - @RequestMapping(value = "processWork", method = RequestMethod.GET) public @ResponseBody DataResponse processWork(@RequestParam("conf") final String value, @RequestParam("dc") final String dc) { // .. some code here SomeOtherClass modifier = new SomeOtherClass(zookClient); List<Map

Multiple WebDriver instances in Selenium without Grid?

一笑奈何 提交于 2019-12-25 02:28:06
问题 Is it possible to use multiple selenium webdrivers locally without using selenium grid to run multiple test at the same time? I am creating multiple instances by calling new FireFoxDriver() but the sessions in the windows seem to interfere with each other. The driver is created and destroyed by the JUnit-Methods shown below. For every Test-class there is one WebDriver but each testcase has a different execution duration. And after the first Test-class has finished and tearDownClass() from

ClassNotFoundException when running ant junit

☆樱花仙子☆ 提交于 2019-12-25 02:26:55
问题 I'm running into this ClassNotFoundException issue when running Junit task below, but this is non eclipse based project running an ant build from command prompt, the build file is pasted below. The exception is below. I have done similar to that of setup here it does not work though, any pointers will be appreciated. Thanks. Class org.apache.tools.ant.util.StringUtils loaded from parent loader (parentFirst) [junit] Testsuite: SampleTest Class org.apache.tools.ant.util.FileUtils loaded from

JUnit tests using a mock database

拟墨画扇 提交于 2019-12-25 01:55:19
问题 I am developping an application that tests different WebServices, and I want it to be as generic as possible. I need to populate database to do JUnit tests, but I don't want these changes to be commited. I know that some in-memory databases like HSQL DB allow testing on a sort of a virtual (or mock) database, but unfortunately I use oracle and I cannot change it now because of my complex data tables structure. What is the best practice you suggest? Thanks. 回答1: First of all, HSQL and

Find an element by text and get xpath - selenium webdriver junit

寵の児 提交于 2019-12-25 01:53:51
问题 I have a table with 9 rows and 6 columns in my webpage. I want to search for a text "MakeGoodDisabled-Programwise_09_44_38_461(n)" and get the xpath of the cell. I have used the following but it fails because it is not able to find the text on the page. Can you please help? I am using Selenium Webdriver Junit to code this. List < WebElement > links = driver.findElements(By.tagName("td")); Iterator < WebElement > itr = links.iterator(); while (itr.hasNext()) { String test = itr.next().getText(

JBoss Embedded jUnit testing for EJB : NameNotFoundException

佐手、 提交于 2019-12-25 01:48:59
问题 I'm newbie in EJB and jUnit, and I'm trying to do Embedded testing for the simple EJB-project that running by jBoss AS 7.1.1.Final. I've written this test: package com.staff.test.logic; import java.io.File; import javax.ejb.embeddable.EJBContainer; import javax.naming.Context; import javax.naming.NamingException; import org.jboss.as.embedded.EmbeddedServerFactory; import org.jboss.as.embedded.StandaloneServer; import org.junit.Before; import org.junit.Test; import com.staff.main.logic

Android test project fails to build under Ant, OK in Eclipse

你说的曾经没有我的故事 提交于 2019-12-25 01:44:59
问题 I am trying to set up a CI build server for an Android app project and its JUnit test project. I've generated the appropriate build.xml files for both app and test projects. Both projects build and execute fine under Eclipse. However, when I try to do ant debug on the test project without having first built both projects with Eclipse, I get several [javac] errors saying error: cannot find symbol which refer to classes in the app project. I think this is a difference between the classpath that

How to display a directory full of junit test result files

若如初见. 提交于 2019-12-25 01:17:43
问题 As part of testing in the cloud, I plan to copy my test results (I happen to be using gradle) as xml out of a short lived container to an s3 bucket. I am wondering what is the best approach for making use of the bucket full of test results and if anyone has ideas for how to get the most of these results with the least custom code, etc. In the past I have handled this with XSLT to make the XML into HTML but that approach feels like more work than I'd like to have to do. Has anyone solved this