junit4

create POM with junit 4

假如想象 提交于 2019-11-29 18:35:57
问题 I use Maven 3.0.4 and want to have junit 4 by default. My projects are created with the command : $>mvn archetype:create -DgroupId=my.group.id -DartifactId=myArtifactId -DpackageName=my.package.name This puts a depency to junit version 3.8.1 in the created pom.xml, dispite the fact that verion 4.8.1 is already present. There are no dependencies to junit in my global settings.xml, and I haven't a local .m2/repository/settings.xml. I don't want to remove the old version 3.8.1., but want that

Does Spring @DirtiesContext reload Spring context?

梦想与她 提交于 2019-11-29 18:33:37
问题 I have a test class that looks like @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:/test-context.xml"}) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public abstract class TestClass { @Rule @Resource public JUnitRuleMockery jMockContext; public void test1() { //Expectations and test } public void test2() { //Expectations and test } } and in test-context.xml I define the JUnitRuleMockery plus several mock objects through a factory-method ,

How to programmatically execute a test suite using JUnit4?

那年仲夏 提交于 2019-11-29 18:06:48
问题 I am trying to invoke a JUnit Test suite using the API. I know that you can suite up test classes using the following: @RunWith(Suite.class) @Suite.SuiteClasses({ Test1.class, Test2.class, ... }) But, is there a way to trigger the entire suite using the Java API, using JUnitCore for example? For example, you can trigger a test by using the following code: Runner r = try { r = new BlockJUnit4ClassRunner(Class.forName(testClass)); } catch (ClassNotFoundException | InitializationError e) { //

Ehcache shutdown causing an exception while running test suite

我的梦境 提交于 2019-11-29 16:55:10
问题 I'm experiencing the following problem. I have a test suit in my project and each individual test runs fine. However when I run them as a suite I some of them fails with the following exception: Caused by: java.lang.IllegalStateException: The dao Cache is not alive (STATUS_SHUTDOWN) at net.sf.ehcache.Cache$CacheStatus.checkAlive(Cache.java:4269) at net.sf.ehcache.Cache.checkStatus(Cache.java:2703) at net.sf.ehcache.Cache.get(Cache.java:1576) at org.springframework.cache.ehcache.EhCacheCache

JUnit4 run all tests in a specific package using a testsuite

China☆狼群 提交于 2019-11-29 16:29:19
问题 Is this possible in JUnit4? In JUnit3, I would do the following: public class MyTestSuite { public static Test suite() throws Exception { doBeforeActions(); try { TestSuite testSuite = new TestSuite(); for(Class clazz : getAllClassesInPackage("com.mypackage")){ testSuite.addTestSuite(clazz); } return testSuite; } finally { doAfterActions } } ... } 回答1: The takari-cpsuite (originally developed by Johannes Link) offers a classpath-suite which should fit your needs. It allows filtering of

JUnit test not executing all threads created within the test

孤街醉人 提交于 2019-11-29 13:53:56
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 { private int number; Calculator(final int number){ this.number = number; } @Override public void run() {

How to partially mock HttpServletRequest using Mockito

旧巷老猫 提交于 2019-11-29 13:33:47
问题 i am mocking a HttpServletRequest , in servlet call there are new values getting set in request because using same request we are dispaching request to some jsp so request object is used as a input object to servlet as well as output for next page. i mocked all input parameters , but for all request.setAttribute() , my code is doing nothing as it's a mocked class , say if i have request.setAttribute(a,"10") System.out.println("a = " + request.getAttribute("a")); i get null cuz i haven't given

Maven Failsafe Classpath

一世执手 提交于 2019-11-29 11:31:09
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 entities are read-only"); } where NotUpdatableException is my custom exception class. The IT for this code

Espresso how to wait for some time(1 hour)?

可紊 提交于 2019-11-29 11:29:08
问题 In my test case I have to record for 1 hour, in robotium solo.sleep(600000) had done my work, but In espresso I am confused with IdlingResource concept. I have to start recording and wait for some time(depending on the type of test) 15mins, 60mins etc. Equivalent code in robotium solo.clickOnView(solo.getView("start_record")); solo.sleep(duration * 60 * 1000); solo.clickOnView(solo.getView("stop_record")); I tried to use it like this in espresso @RunWith(AndroidJUnit4.class) @SmallTest public

JUnit - assertSame

会有一股神秘感。 提交于 2019-11-29 10:59:45
问题 Can someone tell me why assertSame() do fail when I use values > 127? import static org.junit.Assert.*; ... @Test public void StationTest1() { .. assertSame(4, 4); // OK assertSame(10, 10); // OK assertSame(100, 100); // OK assertSame(127, 127); // OK assertSame(128, 128); // raises an junit.framework.AssertionFailedError! assertSame(((int) 128),((int) 128)); // also junit.framework.AssertionFailedError! } I'm using JUnit 4.8.1. 回答1: The reason is the autoboxing of Java. You use the method: