junit4

junit TestWatcher failed and finished methods firing time

那年仲夏 提交于 2019-12-11 10:38:55
问题 I am writing some functional tests with webdriver and executing them with JUnit. I am trying to make use of TestWatcher class so everytime an event occurs a specific action could be done. I am overriding the finished and failed methods, but it seems to be that these are fired virtually simultaneously, so the driver has been already disposed by finish method before the failed method could do it's stuff. The TestWatcher is following: public class TestRules extends TestWatcher { private static

Why is my Spring JUnit Test Rule not running?

扶醉桌前 提交于 2019-12-11 10:23:48
问题 I've been struggling to find an obvious solution to why the linked code will not run JUnit TestRules. I've created a success case where TestRules execute, and a failure case that shows a situation where TestRules fail. Is anybody able to see why the TestRules are not being picked up? It's not just Spring's TestRule not being picked up. It seems to be all TestRules, as demonstrated by MyTestRule.java in the source code. Running mvn clean install on the success case, will see all tests passing.

Creating a JUnit testsuite with multiple instances of a Parameterized test

一个人想着一个人 提交于 2019-12-11 08:28:52
问题 I want to create a TestSuite from multiple text files. Each textfile should be one Test and contains the parameters for that test. I have created a Test like: @RunWith(Parameterized.class) public class SimpleTest { private static String testId = "TestCase 1"; private final String parameter; @BeforeClass public static void beforeClass() { System.out.println("Before class " + testId); } @AfterClass public static void afterClass() { System.out.println("After class " + testId); } @Before public

Ordeal trying to use JUnit to test a Library

点点圈 提交于 2019-12-11 08:20:33
问题 I feel there is much confusion around how to use JUnit to test an Android Library project. I will describe all the errors I encountered so far(for the sake of other programmers trying to do the same) and at the end I will specify my last and current problem. Since a Library is not an Application, it does not produce an .apk file in the bin directory, just a .jar file, and you need an .apk to use Android JUnit testing So you definitely need to create a new project for the tests, follow this

executing a java class file from ant script

陌路散爱 提交于 2019-12-11 07:33:49
问题 I need to run a java class (actually a test case) from ant script. Is it possible to do so? 回答1: At the most basic level you could use the ant java task to do this. But you tagged with junit4 - can you not use the ant junit task? 回答2: To execute java class, you can use java task http://ant.apache.org/manual/Tasks/java.html To execute junit test cases: http://ant.apache.org/manual/tasksoverview.html#testing 回答3: Try the java task. If you want to run tests, you might want to take a look at

How to include multiple categories in junit4?

点点圈 提交于 2019-12-11 07:27:09
问题 I want to include multiple categories for a junit runner. Java Code @RunWith(Categories.class) @IncludeCategory(IMAP.class , POP.class) @SuiteClasses({MailTestSuites.class}) public class TestSuiteRunner{ } I want to run my test suite for these two categories only. I have categories for mail suite like "IMAP,POP , SMTP , POP3". Now , I want to run only "IMAP , POP" category suites only. How can I run with junit? 回答1: Up to version JUnit 4.11, @IncludeCategory and @ExcludeCategory only support

Testing @RooJavaBean class in Eclipse IDE with JUnit

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:16:29
问题 I use Spring Roo to generate getters/setters. When I update my class under test and then run JUnit tests from Eclipse IDE (STS), it does't see changes I have made. For example: java.lang.NoSuchMethodError: com.example.web.forms.UserRegistrationForm_Roo_JavaBean.ajc$interMethodDispatch1$com_datefitting_web_forms_UserRegistrationForm_Roo_JavaBean$com_example_web_forms_UserRegistrationForm$setName(Lcom/datefitting/web/forms/UserRegistrationForm;Ljava/lang/String;)V` After running roo>perform

How would you implement so each Test class logs output to a separate file?

…衆ロ難τιáo~ 提交于 2019-12-11 07:08:54
问题 Using Java, with either TestNG or JUnit, if you wanted to log some information gathered during a test to a file, and have each test class (such as TestClass1.class ) keep a separate output file named after the class like so: TestClass1.log How would you implement this kind of thing? I know log4j can log the class name in a 'per line' of output in a single file but I want outputs for each class to be in separate files. Also, log4j can log output to different files based on package name.

PowerMock + EasyMock: private void method without invokation

跟風遠走 提交于 2019-12-11 06:36:26
问题 Good time! I need to substitute the class' private void method with a mock implementation, and can't to figure out how to do this. I've tried to use such a construction: Test test = PowerMock.createPartialMock(Test.class, "setId"); PowerMock.expectPrivate(test , "setId", EasyMock.anyLong()).andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { return null; } }); PowerMock.replay(test); but the internal PowerMock's class called WhiteBox invokes my "setId" method

Upgrade from JUnit 4 to JUnit 5 in intellij with gradle

僤鯓⒐⒋嵵緔 提交于 2019-12-11 05:53:59
问题 I want to convert my Gradle project test from JUnit 4 to JUnit 5. As there are a lot of tests, I don't want to convert them all at the same time. I try to configure my build.gradle like this: apply plugin: 'java' compileTestJava { sourceCompatibility = 1.8 targetCompatibility = 1.8 } repositories { mavenCentral() } dependencies { testCompile("junit:junit:4.12") testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0-M2' testRuntime("org.junit.vintage:junit-vintage-engine:4.12.0-M2")