junit4

Gradle equivalent for Maven Surefire surefire.forkNumber

怎甘沉沦 提交于 2019-12-14 03:04:22
问题 I'm migrating a codebase from Maven to Gradle. In our integration test we use FailSafe ability to run the tests in parallel in multiple threads. FailSafe is setting a system property name surefire.forkNumber with the number of the specific fork the current thread runs. Is there equivalent parameter when running JUnit with Gradle? 回答1: The test task in Gradle has the property maxParallelForks to instruct the tests to run in parallel. To pass a property from the command-line to set the value we

JUnit 4.12: testing util classes

↘锁芯ラ 提交于 2019-12-14 01:51:58
问题 I have a maven project in Eclipse called TdkUtils, with this pom.xml: This is a utils project. So I want to create a jar, put it in the repository and use it in another projects. In this project I have this class: @Service("smsService") public class TdkSMSSender { ... } and a JUnit test. @RunWith(SpringJUnit4ClassRunner.class) public class TdkSMSSenderTest { @Autowired private TdkSMSSender smsService; @Test public void createStripeCustomer() throws Exception { assertTrue (true); } } But

How to setup JUnit testing in Gluon Project with Gradle

廉价感情. 提交于 2019-12-13 20:03:30
问题 I am trying to setup JUnit testing in my Gluon JavaFX Application. I am using the Gluon Eclipse Plugin with Gradle and Java 8. My build.gradle file looks like this: buildscript { repositories { jcenter() } dependencies { classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b10' } } apply plugin: 'org.javafxports.jfxmobile' repositories { jcenter() } dependencies { compile 'com.gluonhq:ignite-dagger:1.0.0' compile 'org.elasticsearch:elasticsearch:1.6.0' compile 'ch.qos.logback:logback-classic:1.1

How do I delete all JPA entities?

元气小坏坏 提交于 2019-12-13 19:48:45
问题 In my testing code I need to have a blank/empty database at each method. Is there code that would achieve that, to call in the @Before of the test? 回答1: Actually you always can use JPQL, em .createQuery("DELETE FROM MyEntity m") .executeUpdate() ; But note, there is no grants that entity cache would be cleaned also. But for unit-test purposes it is look like good solution. 回答2: In my testing code I need to have a blank/empty database at each method. I would run the test methods insider a

How to unit test to give coverage of exception branches

淺唱寂寞╮ 提交于 2019-12-13 17:46:25
问题 I write unit tests with JUnit4 and Mockito for my application and I want make full coverage. But I don't fully understand how cover exception branches. For example: try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } How I can invoke from tests exceptions? 回答1: While you may not easily be able to insert an exception into Thread.sleep in particular, because it's being called statically instead of against an injected instance, you can easily stub injected

Testing with Robolectric in Eclipse

岁酱吖の 提交于 2019-12-13 16:26:42
问题 I am trying to run a simple test with Robolectric in eclipse . I followed this tutorial, but got this error : java.lang.RuntimeException: java.io.FileNotFoundException: C:\Vishal\Development\workspace>\AndroidHelloWorldTester.\AndroidManifest.xml not found or not a file; it >should point to your project's AndroidManifest.xml Then as per Eugen's advice at here, I tried to extend the RobolectricTestRunner class as per instructed here but got this error :- (well I couldn't write the constructor

EclEmma Code Coverage Ignore Junit Tests

末鹿安然 提交于 2019-12-13 15:12:59
问题 The only way I have found to not check code coverage on my JUnit tests is to right click on the package, choose Coverage as..., and then choose configuration. Then I can unclick my test package. I have tried every possible combination to exclude test under the general preferences/java/code coverage/exclude and not seen any changes. I always put my tests in a separate test source folder with the same package name as my src code. Do I really have to configure every single project to ignore my

Unsupported major.minor version 51.0 on Junit, but not web app

核能气质少年 提交于 2019-12-13 14:30:25
问题 I'm running Junits on our app server that fail with Unsupported major.minor version 51.0 . But, the web application then builds, deploys, and runs fine. I don't understand how this can happen. My maven compiler's config looks like this: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <verbose>true</verbose> <fork>true</fork> <source>1.7</source> <target>1.7</target> <executable>${JAVA_1_7_HOME}/bin

Surefire is not picking up Junit 4 tests

巧了我就是萌 提交于 2019-12-13 12:24:10
问题 I cannot get Maven Surefire to execute my JUnit 4 tests even after I tried all the advices from another post. My POM: <project> <modelVersion>4.0.0</modelVersion> <groupId>maven-test</groupId> <artifactId>maven-test</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.junit</groupId> <artifactId>com.springsource.org.junit</artifactId> <version>4.4.0</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache

Testing EditText errors with Espresso on Android

て烟熏妆下的殇ゞ 提交于 2019-12-13 11:53:59
问题 I want to test if an EditText field has an error (set with editText.setError("Cannot be blank!")). I've created an Espresso test case with the new AndroidStudio 2.2 feature, to record Espresso tests. So the code is pretty much auto-generated. But for now it only checks if the editText is displayed. @RunWith(AndroidJUnit4.class) public class CreateNoteActivityTitleCannotBeBlank { @Rule public ActivityTestRule<CreateNoteActivity> mActivityTestRule = new ActivityTestRule<>(CreateNoteActivity