parameterized - Spring junit exception -


This is my test class. The exception is being followed when I try to run the test method.

I am using parmeterized for testing for various inputs. AM to use maven.not using AM

  exception: java.lang.Exception: Test class organization absolutely must have a public no-argument constructor .junit.runners.BlockJUnit4ClassRunner.validateZeroArgConstructor org.junit.runners.BlockJUnit4ClassRunner.validateConstructor (BlockJUnit4ClassRunner.java:124) at org.junit.runners.ParentRunner.validate (ParentRunner.java355) at (BlockJUnit4ClassRunner.java147) org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors (BlockJUnit4ClassRunner.java:103) On .junit.runners.ParentRunner & Lt; Init & gt; (ParentRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner & Lt; Init & gt; (BlockJUnit4ClassRunner.java:57) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner. & Lt; Init & gt; Sun.reflect.NativeConstructorAccessorImpl.newInstance0 (sunrise) on sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java.5) at sun.reflect.DeligatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java45) java (Sprite NgJUnit4ClassRunner.java:104) on org.junit.internal.builders.AnnotatedBuilder.runnerForClass on .lang.reflect.Constructor.newInstance (Constructor.java:526) org.junit.internal.builders.AnnotatedBuilder.buildRunner (AnnotatedBuilder.java:29) (AnnotatedBuilder.java 21) on org.junit.runners.model.RunnerBuilder.safeRunnerForClass (RunnerBuilder.java:59) on org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass  

  @RunWith (SpringJUnit4ClassRunner.class) @ContextConfiguration (places = {"classpath: config / applicationContext-http-int.xml", "classpath: config / web forms Dn- config.xml "}) public class TestValidatePolicy extends BaseT Este {@ Attovayr personal service; Private string number; Private string code; @ Paramets public static collection Prime () {return Arrays.asList (new Object [] [] {{ "8001060001045", "86502"}, { "8001060001039", "85902"}}); } Public TestValidate Policy (string number, string code) {this.Number = number; this. Code = code; } @Test public invalid testValidatePolicyDetails () throws an exception {string xmlValue = getStringFromStream ("validatePolicy.xml"); Assert.assertEquals (xmlValue, Service.getDetails (number, code)); }}  

Your test class is a constructor with two arguments:

   Test class  
  Public TestValidatePolicy () {...}     

... or two logic Get rid of the constructor

- But you are trying to run parametrad jUnit4 tests. To specify the parameterized runner, they require @Ravwin:

  @RunWith (parameterized.class)  

... but you may not have a spring Runner:

  @RunWith (SpringJUnit4ClassRunner.class)  

until two @RunWith annotations (as I know) Is there, and there is no parametricspringjunit 4 classifier . So, what to do?

I get a suggestion

Use:

  @RunWith (parameter.class)  

since you can not use the spring runner, you set manually similar behavior:

  @RunWith (Parameterized.class) @ContextConfiguration (locations = { "classpath: applicationContext.xml"} ) Public class EmailTest {Personal testContextManager testContextManager; @halfped set-up contact () throws an exception before {// This is the place where there is magic, we actually do "by hand" which the spring runner does for us, // reads for the Java Doc class To know what this does, method names are quite accurate, though it is. TestContextManager = New TestContextManager (getClass ()); This.testContextManager.prepareTestInstance (this); } @Paramats Public Static Collections & lt; Object [] & gt; Data () {...}  

Comments