junit

How to mock static method in Java?

余生长醉 提交于 2019-12-19 08:54:57
问题 I have a class FileGenerator , and I'm writing a test for the generateFile() method that should do the following: 1) it should call the static method getBlockImpl(FileTypeEnum) on BlockAbstractFactory 2) it should populate variable blockList from the subclass method getBlocks() 3) it should call a static method createFile from a final helper class FileHelper passing a String parameter 4) it should call the run method of each BlockController in the blockList So far, I have this empty method:

I need my Spring Boot WebApplication to restart in JUnit

拟墨画扇 提交于 2019-12-19 08:19:10
问题 Without going into excruciating detail, I am having an issue when I run my Junit tests all at once. If I run them class by class, everything is great! Otherwise I have trouble because I cannot restart my WebApplication inbetween junit-test-class. This causes me to have Zookeeper server clients in my WebApplication that hang around after I go through the shutdown and startup of the Zookeeper server in-between classes. Those Zookeeper server clients can take a while to resync with server and

Running jenkins gives “package org.junit does not exist”

∥☆過路亽.° 提交于 2019-12-19 08:16:29
问题 Can any one please help me with that error? build-project: [echo] AntProject: /root/.jenkins/jobs/Ant/workspace/build.xml [javac] Compiling 2 source files to /root/.jenkins/jobs/Ant/workspace/bin [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:3: package org.junit does not exist [javac] import static org.junit.Assert.*; [javac] ^ [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:5: package org.junit does not exist [javac]

Mocking EJB injection in tests

岁酱吖の 提交于 2019-12-19 08:12:55
问题 Whenever I want to test a class which uses resource injection I end up including a constructor that will only be used within the test: public class A { @EJB B b; // Used in tests to inject EJB mock protected A(B b) { this.b = b; } public A() {} // Method that I wish to test public void foo() { b.bar(); } } Is there another way of mocking resource injection or this is the correct pattern to follow? 回答1: you could use easy gloss to that effect, it mocks the EJBs injection system. another way is

New to Ant, ClassNotFoundException with JUnit

帅比萌擦擦* 提交于 2019-12-19 07:23:26
问题 I've been scratching my head over this for a while now (Googled a bunch, looked through other related SO posts to no avail). I have a Java program comprised of two files, Logic and Tests . Tests contains about a hundred JUnit tests, and I've gotten 100% success rate with said tests by calling javac *.java followed by java org.junit.runner.JUnitCore Tests . However when I run my build.xml with a simple ant -verbose test (in order to follow the output since I'm new to all this), I get the

POI Appending .0 while reading numeric data from excel

北城以北 提交于 2019-12-19 07:19:08
问题 I am using POI HSSF to read excel data and I am using JUnit to check the data against database proc RefCursor. The Junit test fails as the numeric data from the Refcursor for example 100 are compared against the data in the excel sheet 100 but it fails as the POI reads it as 100.0. InputStream fileInputStream = Testdb.class.getClassLoader().getResourceAsStream(fileName); //retrieve number of columns and rows int numRows=0, numCols=0, i, j, minColIndex=0, maxColIndex=0; POIFSFileSystem

java.lang.exception no runnable methods junit

风格不统一 提交于 2019-12-19 06:04:28
问题 I have a suite, inside which I have added the test class. I am using surefire to run my JUnits. My test class ends with test and the methods has @test annotations to it. How can this problem be resolved? 回答1: Here are various suggestions for this incomplete question (for those unfortunate enough to be brought here by google looking for an answer to this common issue): if using Junit4.x, just use annotations (@Test); don't create a test suite: see this question for details. original question

Class teardown in junit 3?

*爱你&永不变心* 提交于 2019-12-19 06:03:13
问题 We have a lot of integration tests written using JUnit 3 , though we're now running them with 4.4 . A few of these have a need for a tearDown method that runs after all the tests in the class are complete (to free some common resources). I see that this can be done in junit 4 with @AfterClass (org.junit). However, mixing this into existing junit 3 tests that extend TestCase (junit.framework.*) doesn't seem to work. [BTW is there a migration tool yet? Question 264680 indicated there wasn't one

Failed to retrieve PlatformTransactionManager for @Transactional test for test context

故事扮演 提交于 2019-12-19 05:53:23
问题 Whhen trying to test caching capabilities of Hibernate's (version 4) EHCache between transactions - it fails: Failed to retrieve PlatformTransactionManager for @Transactional test for test context . Test @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { ApplicationConfig.class, CachingConfig.class }, loader = AnnotationConfigContextLoader.class) @PersistenceContext @Transactional public class EHCacheTest extends AbstractTransactionalJUnit4SpringContextTests {

Failed to retrieve PlatformTransactionManager for @Transactional test for test context

守給你的承諾、 提交于 2019-12-19 05:52:06
问题 Whhen trying to test caching capabilities of Hibernate's (version 4) EHCache between transactions - it fails: Failed to retrieve PlatformTransactionManager for @Transactional test for test context . Test @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { ApplicationConfig.class, CachingConfig.class }, loader = AnnotationConfigContextLoader.class) @PersistenceContext @Transactional public class EHCacheTest extends AbstractTransactionalJUnit4SpringContextTests {