junit

TAP::Harness timing issue with TAP::Formatter::JUnit

佐手、 提交于 2019-12-23 14:22:05
问题 I have a set of scripts that produces a JUnit output for Jenkins. The code I execute looks like this (this is just a snippet so you get the idea) : #!/usr/bin/env perl use strict; use warnings; use Test::More; use TAP::Harness; use Test::Builder; my $runner = sub { my ($harness,$test) = @_; sleep(2); my $builder = Test::Builder->new; $builder->reset; $builder->output( \my ($out) ); $builder->failure_output( \$out ); $builder->todo_output( \$out ); $builder->is_eq($test,'test', 'Test is test')

How to set custom test execution order for a test suite in JUnit5?

孤街醉人 提交于 2019-12-23 13:58:39
问题 I have a large set of tests on JUnit5, which I run in parallel in several threads. There is also information about the time of each test. I want to run at the beginning of the longest tests, and leave the fastest at the end to optimize common execution time. I have not found a way to do this in JUnit5. In version 5.4 there is an org.junit.jupiter.api.MethodOrderer interface which allows you to write a test sorter within a test class. And connect to the test class via the annotation org.junit

How do I get multiple MockFor working in Groovy?

情到浓时终转凉″ 提交于 2019-12-23 13:23:07
问题 I am trying to get multiple mocks working in groovy. The only way I have managed to get this working is to create my own kind of mock - adding a meta method. I have tried using nested use statements and also tried one use and one proxy with verify, neither of which worked. Both of these returned a failure - "junit.framework.AssertionFailedError: No more calls to 'pop' expected at this point. End of demands." import groovy.mock.interceptor.MockFor import org.junit.Test class MockTest { //

Spring boot test with @DirtiesContext BEFORE_CLASS

社会主义新天地 提交于 2019-12-23 13:02:26
问题 Hello I recently updated my spring boot application and noticed new feature ( DirtiesContext.ClassMode.BEFORE_CLASS), that seems fit my needs, because I had the problem with reloading bean with method annotated @RabbitListener, for some reason Spring reloaded that bean, but old bean was using as rabbit listener. (See here) My code: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes ={ServerConfig.class,ServerThroughAMQPBrokerRabbitMQIntegrationTestConfig.class})

mock static without @RunWith(PowerMockRunner.class)

微笑、不失礼 提交于 2019-12-23 12:53:09
问题 I have folowing code: @RunWith(PowerMockRunner.class) @PrepareForTest({RequestUtils.class, OsgiUtil.class}) @PowerMockIgnore({"*"}) public class MyTest ... @Test public somMethod(){ .... mockStatic(RequestUtils.class); when(RequestUtils.getLocale(request)).thenReturn(locale); } } How to replace this code so that it work without @RunWith(PowerMockRunner.class) ? According the cause described in following link I cannot use @RunWith(PowerMockRunner.class) 回答1: Take a look on this discussion:

Is it possible to test an Abstract activity with Robolectric

十年热恋 提交于 2019-12-23 12:43:27
问题 I use abstract activity classes in my code to well, abstract away some features from the activity classes. I'm trying to test the abstract activity classes using Robolectric and the gradle-android-test-plugin using subclasses that extend the abstract class. I can't seem to get it to work though. Does anyone have any experience in this area and is it even possible ? Basic structure is : @RunWith(RobolectricGradleTestRunner.class) public class AbstractActivityTest { private ActivityTest

How to use PowerMock with Arquillian?

狂风中的少年 提交于 2019-12-23 12:35:07
问题 I tried to use PowerMockRule in a JUnit test that uses arquillian but I get java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalStateException: PowerMockRule can only be used with the system classloader but was loaded by ModuleClassLoader for Module I want to test something like this: @RunWith(Arquillian.class) @PrepareForTest(WARRRAworkffsTest.class) public class WARRRAworkffsTest { @Rule public PowerMockRule rule = new PowerMockRule(); @Deployment(testable=true) public static

Testing for Exceptions using JUnit. Test fails even if the Exception is caught

北城以北 提交于 2019-12-23 12:27:25
问题 I am new to testing with JUnit and I need a hint on testing Exceptions. I have a simple method that throws an exception if it gets an empty input string: public SumarniVzorec( String sumarniVzorec) throws IOException { if (sumarniVzorec == "") { IOException emptyString = new IOException("The input string is empty"); throw emptyString; } I want to test that the exception is actually thrown if the argument is an empty string. For that, I use following code: @Test(expected=IOException.class)

Android Instrumentation test java.lang.UnsatisfiedLinkError on using AndroidJunitRunner and AndroidJUnit4

喜欢而已 提交于 2019-12-23 10:28:17
问题 I am using robolectric in our unit tests. Recently in our project, we are adding a new dependency from zendesk. repositories { maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' } } compile group: 'com.zendesk', name: 'sdk', version: '1.3.0.1' Now we have not even referenced any class from this library and we are getting exceptions in our robolectric unit tests just by adding this dependency. I thought the problem is in our project, but its also occurring on a sample robolectric

Testing that an Activity returns the expected result

大兔子大兔子 提交于 2019-12-23 09:58:43
问题 I have the following Activity: package codeguru.startactivityforresult; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class ChildActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.child); this.resultButton = (Button) this.findViewById(R.id.result_button); this.resultButton.setOnClickListener