junit4

Testing drag-and-drop files onto application

强颜欢笑 提交于 2019-12-20 11:36:54
问题 I am looking for a method to perform a drag-and-drop of a file/multiple files onto my application from a unit test. For example selecting some files in Windows Explorer, drag them and drop them on my application. I am capable of testing drag-and-drop behavior between two components in my application (see below - feel free to indicate if you know a better way), but I have no idea how to do the same when the data has to come from outside my application. I thought about using the debugger to

Difference between stub and when in mockito

 ̄綄美尐妖づ 提交于 2019-12-20 10:18:50
问题 I am new to mockito. need to know difference between stub and when 1. stub(cpproxy.getBinList()).toReturn(gettestbins()); 2. when(cpproxy.getBinList()).thenReturn(gettestbins()); whats the difference between these two? 回答1: Actually they are technically the same. When Mockito was first created, we were talking about stubs, so the vocabulary followed that idea. Later people thought it was better to think in interactions rather that technical terms, so the vocabulary followed the when ... then

JUnit assertions : make the assertion between floats

我只是一个虾纸丫 提交于 2019-12-20 10:18:04
问题 I need to compare two values : one a string and the other is float so I convert the string to float then try to call assertEquals(val1,val2) but this is not authorized , I guess that the assertEquals doesn't accept float as arguments. What is the solution for me in this case ? 回答1: You have to provide a delta to the assertion for Floats: Assert.assertEquals(expected, actual, delta) While delta is the maximum difference (delta) between expected and actual for which both numbers are still

Selenium 2 and JUnit4: How to capture screenshot on exception?

柔情痞子 提交于 2019-12-20 09:38:27
问题 I want to capture a screenshot only upon unexpected exception. 回答1: Note.- This answer could be outdated. The answer is based on Selenium 2.15 Using TestWatcher does the trick (the unit test must extend following BaseTest ): public abstract class BaseTest { // ... protected WebDriver driver; @Rule public TestRule testWatcher = new TestWatcher() { @Override public void starting(Description desc) { LOG.info("Launching browser..."); driver = Utils.getFirefoxDriver(); } @Override public void

Java/ JUnit - AssertTrue vs AssertFalse

让人想犯罪 __ 提交于 2019-12-20 08:24:16
问题 I'm pretty new to Java and am following the Eclipse Total Beginner's Tutorials. They are all very helpful, but in Lesson 12, he uses assertTrue for one test case and assertFalse for another. Here's the code: // Check the book out to p1 (Thomas) // Check to see that the book was successfully checked out to p1 (Thomas) assertTrue("Book did not check out correctly", ml.checkOut(b1, p1)); // If checkOut fails, display message assertEquals("Thomas", b1.getPerson().getName()); assertFalse("Book was

JUnit testing for IO

依然范特西╮ 提交于 2019-12-20 05:47:05
问题 I am new here and new to junit testing. I have a class with two methods and I want to write unit tests for it. I am not sure how to start I read some basic tutorials but I am not able to start some how. Can anyone of you provide me some basic skeleton to start with. My class is public class CreateCSV { MyWriter csvOutput = null; public void createSortedSet ( final HashMap< String, Signal > map, final long totalSize, final long totalSizewithHeader, File file ) { ArrayList< Signal > messages =

error compiling junit test with expect exception

ぐ巨炮叔叔 提交于 2019-12-20 05:13:23
问题 I am having difficulty using junit 4's expected annotation to look at exceptions. I can't compile the code because there's an unhandled exception. Here's a simple example that creates the situation: import static org.junit.Assert.*; import java.io.UnsupportedEncodingException; import org.junit.Test; public class Simple { @Test(expected=UnsupportedEncodingException.class) public void simpleTest(){ String a = ""; a.getBytes("UTF-123"); } } I get a compilation error saying "Unhandled exception

JUnit @AfterClass run time is added to a poor testcase :(

时光总嘲笑我的痴心妄想 提交于 2019-12-20 02:56:18
问题 I'm facing a slight JUnit inconvenience regarding the run time for each test to run. I have an @AfterClass annotation and the last test that runs will get it's runtime added to it's. So the report will incorrectly show a long run time for the poor test that happens to be run last. Is there a way to exclude its run time from the last test? 回答1: This is an issue with Eclipse, not junit. If we use this as an example: public class TimingTest { @Test public void test1() { System.out.println("test1

How to parameterize junit Test Suite

∥☆過路亽.° 提交于 2019-12-19 09:43:19
问题 Is it possible to parameterize a TestSuite in junit 4 ? For declaring a class as a test suite I need the annotation @RunWith(Suite.class) , but the same annotation is also needed to declare the test as parameterized: @RunWith(Parameterized.class) so I cannot add both to the same class. I found a similar question in this site that did not help much. So far, all the examples I have found explain how to parameterize simple unit tests, not a complete test tuite. 回答1: I believe the basic answer is

JUnit3 and Junit4 XML Reports with Maven

无人久伴 提交于 2019-12-19 06:05:24
问题 I am trying to figure out how to use the supposed reporting capabilities of JUnit (3 and 4) in conjunction with Maven, but Google searches aren't turning up much in the way of how to actually run JUnit (via Maven), get a report for each test (or all tests) and what format it will be in. So, my multi-part questions is: 1.) What sort of XML format is JUnit (3/4) capable of outputting? 2.) What sort of calling convention/arguments are required for JUnit to output these reports? 3.) Where are the