junit4

Junit4 and TestNG in one project with Maven

前提是你 提交于 2019-11-28 09:04:32
问题 To run them together there are few options available but I have chosen using different profiles for Junit and TestNG. But now problem is with excluding and including test cases. Since if we add testNG dependency to main project in maven it will skip all Junit,I have decided to put it in separate profile. So I am excluding TestNG tests in default(main) profile from compiling using following entry in pom.xml : <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler

Can I apply a time limit for all the tests in the suite

☆樱花仙子☆ 提交于 2019-11-28 08:12:01
问题 Is there a way in JUnit to define a global timeout/limit for all the tests included in the suite. Well, let me to explain this a little. I want to introduce a junit test suite into the build system of a legacy project that would be run on every build. The suite should consist of fast running unit tests, but the project has mixed set of integration and unit tests in it's tests source folder. So what I am aiming for is introducing a central test suite for unit tests that only contains those

JUnit test not executing all threads created within the test

时间秒杀一切 提交于 2019-11-28 07:54:37
问题 I wrote a simple example for threading which generates tables for numbers starting from 1 to 20. when I tested it with main method it executes all the threads (prints all the messages), while all threads are not being run (all messages are not being printed) most of the times (sometimes it runs all the threads) when doing the same with JUnit test. I think there should not be any difference in terms of output. Here is the class with main method: public class Calculator implements Runnable {

How to select or change JUnit version in Eclipse?

你离开我真会死。 提交于 2019-11-28 07:23:31
问题 Basically the source code I am using requires a very specific JUnit test version such as: lucene-test-framework-XX.jar The compiled Lucene test-framework library. Depends on junit 4.10.x (not 4.9.x, not 4.11.x), and Apache Ant 1.7.x (not 1.6.x, not 1.8.x) However, I am new to Eclipse, where and how do I change the JUnit to 4.10.x? Thanks a lot in advance! 回答1: I have changed mine out in the past by (specifically) removing the prior, then adding the specific JUnit (External) JAR in my project

How to exclude all JUnit4 tests with a given category using Maven surefire?

亡梦爱人 提交于 2019-11-28 06:56:01
I intend on annotating some of my JUnit4 tests with an @Category annotation. I would then like to exclude that category of tests from running on my Maven builds. I see from the Maven documentation that it is possible to specify a category of tests to run. I want to know how to specify a category of tests not to run. Thanks! You can do this as follows: Your pom.xml should contain the following setup. <configuration> <excludes> <exclude>**/TestCircle.java</exclude> <exclude>**/TestSquare.java</exclude> </excludes> </configuration> If you want regex support just use <excludes> <exclude>%regex[.*

Why cannot I import AndroidJUnit4 and ActivityTestRule into my unit test class?

那年仲夏 提交于 2019-11-28 06:40:38
I'm having trouble importing some of the Android UI testing framework clases - I just can't figure out what is going wrong! This is my class: @RunWith(AndroidJUnit4.class) @LargeTest public class ExampleUnitTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void listGoesOverTheFold() { onView(withText("Hello world!")).check(matches(isDisplayed())); } } But for some reason I get errors 'cannot find symbol ActivityTestRule' and 'cannot find symbol AndroidJUnit4'. I've tried to import them but they cannot be found. The

Maven Failsafe Classpath

落爺英雄遲暮 提交于 2019-11-28 05:33:10
问题 I've started a new project: PostfixSQLConfig. It's a simple Spring Boot application that is essentialy supposed to provide CRUD access for 4 simple databse tables. I wrote the the repository for the first table and some basic integration tests for said repository. Since this particular table should not provide update functionality, I implemented update function as: @Override public void update(@NonNull Domain domain) throws NotUpdatableException { throw new NotUpdatableException("Domain

Maven 3 and JUnit 4 compilation problem: package org.junit does not exist

烂漫一生 提交于 2019-11-28 05:10:23
I am trying to build a simple Java project with Maven. In my pom-file I declare JUnit 4.8.2 as the only dependency. Still Maven insists on using JUnit version 3.8.1. How do I fix it? The problem manifests itself in a compilation failure: "package org.junit does not exist". This is because of the import statement in my source code. The correct package name in JUnit 4.* is org.junit.* while in version 3.* it is junit.framework.* I think I have found documentation on the root of the problem on http://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html but the advice there seems to

Junit SuiteClasses with a static list of classes

☆樱花仙子☆ 提交于 2019-11-28 04:26:34
问题 SuiteClasses will work just fine with a list of classes like {Test1.class,Test2.class} , but when I try to generate a static list of classes, it says incompatible types: required java.lang.Class<?> but found java.lang.Class<?>[] What am I missing? @RunWith(Suite.class) @Suite.SuiteClasses(TestSuite.classes) public class TestSuite { public static Class<?> [] classes; static { classes = new Class<?> [1]; classes[0] = MyTest.class; } } 回答1: That shouldn't really work. You are intended to put the

Where should the integration tests be stored when using the maven-failsafe-plugin?

依然范特西╮ 提交于 2019-11-28 03:26:12
问题 Do I have to place my integration tests under src/test with the rest of my unit tests and just distinguish them by a pattern such as *Integr*Test , *ITTest , or can they be in src/it (as is the case when developing Maven plugins and using the maven-invoker-plugin )? I'm asking this because, to me it looks not clean enough if both unit and integration tests are in the same place, (even if they were to be controlled via a Maven profile). 回答1: First maven-fails-plugin runs by default in another