junit4

Test DAO in java using Junit4 and Hibernate

不想你离开。 提交于 2019-12-24 08:35:10
问题 Testing DAO'm using junit and mainly what I do is start a transaction in hibernate, call the compare function, and then roll back the transaccion.El problem is that if I'm Testing function is a transaction error I can not strip nest, I thought about the idea of ​​implementing DBUnit xml but management does not seem a good idea and less in this instance that I did enough test cases with this method. Anyone have any idea how to fix it without having to use anything other than Junit or hibernate

JUnit Test Suite for Selenium 2

只谈情不闲聊 提交于 2019-12-24 08:26:02
问题 I have converted a Selenium Test Suite into JUnit from Selenium IDE, and trying to execute from eclipse. But there is an error in my script in suite.addTestSuite(Open_Google_IE.class); suite.addTestSuite(Open_Google_FireFox.class); Error message: The method addTestSuite(Class) in the type TestSuite is not applicable for the arguments (Class). Please advise what could be the reason. I have also verified Creating Test Suite in Webdriver and updated test suite but still throws that error. JUnit

Creating multiple unit tests from a loop in Java

三世轮回 提交于 2019-12-24 08:17:39
问题 I'm writing unit tests for my (small) program, and the test cases are specified in around 30 different files. To test it, all I need is a loop that goes over all the files, parse them, and execute what's needed. The problem is that in that case, all of my tests will be considered as one, since it's all in the same function with the @Test notation. Is it possible to split it somehow without having to have a separate function for each test file? The problem with all the tests as one test case,

how to mock ServletActionContext.getRequest() using Mockito we are using Struts2

寵の児 提交于 2019-12-24 08:11:24
问题 I tried something like this but still throwing NullPointerException @RunWith(MockitoJUnitRunner.class) public class MyActionTest extends BaseActionTestCase { @Mock private ServletActionContext context; @Mock private serviceclass serviceMock; @InjectMocks private MyAction action; @Test public void testSave() throws Exception { when(serviceMock.getTaskCode()).thenReturn("tc"); action.save(); verify(serviceMock).saveObject(any(Task.class)); } posting stacktrace: java.lang.NullPointerException at

How to log test pass/fail results of JUnit4 to a file?

偶尔善良 提交于 2019-12-24 04:03:12
问题 When a given JUnit4 test runs, I want it to generate a logfile of all of its TestResults. I do not want to invoke this via CI/ant/maven. I want this to run anytime the JUnit test is called from anywhere. If that is not possible, then I would like to write my own runner which problematically invokes my AllTestSuites class and logs all the results itself. Here would be one of my test classes: public class SimpleTestSuite extends TestCase{ @Test public void simpleTestPass() { assertTrue(true); }

JUnit test fails in Ant with `<junit>` task but passes with `<exec>`?

痴心易碎 提交于 2019-12-24 03:29:54
问题 I am automating my JUnit tests into my Ant build. However, my simple test only passes when run from the IDE and commandline but fails with Ant's <junit> task. When I run it from the commandline (I am technically using the Ant <exec> task) the result is: clean: compile_tests: [javac] Compiling 2 source files to C:\MY_TEMP junit_exec: [exec] JUnit version 4.10 [exec] . [exec] Time: 0.004 [exec] [exec] OK (1 test) [exec] BUILD SUCCESSFUL Total time: 1 second but when I use the <junit> task:

Robolectric, Dagger and compile time $ModuleAdapter creation

限于喜欢 提交于 2019-12-24 02:38:07
问题 Following on from the other questions in my Android TDD series, I have managed to get as far as using Robolectric , Mockito , Maven and ABS to unit test my Android developments. Evidently, I am seemingly pushing my own knowledge boundaries but the Android CI dream is just too alluring. If you can assist with my next problem I would be very grateful, here it is; I am wanting to write an integration test case which takes my application's database from v1 to head. I am using Dagger for DI and to

Spring 3.2.5 error “java.lang.AssertionError: No ModelAndView found” for all my controller Unit Test

狂风中的少年 提交于 2019-12-24 01:28:23
问题 I'm trying to write some unit tests for my controllers in a Spring MVC and i have already error for my unit test : "java.lang.AssertionError: No ModelAndView found. my app and conrollers works correcty. Does anyone have any ideas ? code controller : @Controller public class LoginController { @RequestMapping(value="/loginfailed", method = RequestMethod.GET) public String loginerror(ModelMap model) { model.addAttribute("error", "true"); return "accueilLogin"; } } unit test :

JUnitCore Stopping

大兔子大兔子 提交于 2019-12-23 22:19:28
问题 I want to stop/destroy a running JUnitCore, which is started with JUnitCore.run(Request.aClass(ClassToRun)); Like pleaseStop() on the RunNotifier. Any ideas? http://junit.sourceforge.net/javadoc/org/junit/runner/package-summary.html 回答1: Option 1: the best option is to write your own Runner implementation, inherited from org.junit.runners.BlockJUnit4ClassRunner and declare it in your execution context, for instance as Main Class of a raw Java command line. Get inspired of JUnit source code

Junit4 run a test class a fixed number of times and display results (eclipse)

假如想象 提交于 2019-12-23 18:42:13
问题 I want to be able to run a Test class a specified number of times. The class looks like : @RunWith(Parameterized.class) public class TestSmithWaterman { private static String[] args; private static SmithWaterman sw; private Double[][] h; private String seq1aligned; @Parameters public static Collection<Object[]> configs() { // h and seq1aligned values } public TestSmithWaterman(Double[][] h, String seq1aligned) { this.h = h; this.seq1aligned = seq1aligned; } @BeforeClass public static void