Best junit code snippet using org.junit.runners.ParentRunner.getName
Source:TestSuiteXmlParserTest.java
...145 List<ReportTestSuite> parse = testSuiteXmlParser.parse( new InputStreamReader(byteArrayIs, "UTF-8") );146 assertThat( parse.size(), is( 1 ) );147 ReportTestSuite report = parse.get( 0 );148 assertThat( report.getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );149 assertThat( report.getName(), is( "TestSurefire3" ) );150 assertThat( report.getPackageName(), is( "wellFormedXmlFailures" ) );151 assertThat( report.getNumberOfTests(), is( 4 ) );152 assertThat( report.getNumberOfSkipped(), is( 0 ) );153 assertThat( report.getNumberOfErrors(), is( 0 ) );154 assertThat( report.getNumberOfFailures(), is( 4 ) );155 assertThat( report.getNumberOfFlakes(), is( 0 ) );156 assertThat( report.getTimeElapsed(), is( 0.005f ) );157 assertThat( report.getTestCases().size(), is( 4 ) );158 List<ReportTestCase> tests = report.getTestCases();159 assertThat( tests.get( 0 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );160 assertThat( tests.get( 0 ).getName(), is( "testLower" ) );161 assertThat( tests.get( 0 ).getFailureDetail(),162 is( "junit.framework.AssertionFailedError: <\n"163 + "\tat junit.framework.Assert.fail(Assert.java:47)\n"164 + "\tat wellFormedXmlFailures.TestSurefire3.testLower(TestSurefire3.java:30)\n" ) );165 assertThat( tests.get( 0 ).getClassName(), is( "TestSurefire3" ) );166 assertThat( tests.get( 0 ).getTime(), is( 0.005f ) );167 assertThat( tests.get( 0 ).getFailureErrorLine(), is( "30" ) );168 assertThat( tests.get( 0 ).getFailureMessage(), is( "<" ) );169 assertThat( tests.get( 0 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testLower" ) );170 assertThat( tests.get( 0 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );171 assertThat( tests.get( 0 ).hasError(), is( false ) );172 assertThat( tests.get( 1 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );173 assertThat( tests.get( 1 ).getName(), is( "testU0000" ) );174 assertThat( tests.get( 1 ).getFailureDetail(),175 is( "junit.framework.AssertionFailedError: \n"176 + "\tat junit.framework.Assert.fail(Assert.java:47)\n"177 + "\tat wellFormedXmlFailures.TestSurefire3.testU0000(TestSurefire3.java:40)\n" ) );178 assertThat( tests.get( 1 ).getClassName(), is( "TestSurefire3" ) );179 assertThat( tests.get( 1 ).getTime(), is( 0f ) );180 assertThat( tests.get( 1 ).getFailureErrorLine(), is( "40" ) );181 assertThat( tests.get( 1 ).getFailureMessage(), is( "&0#;" ) );182 assertThat( tests.get( 1 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testU0000" ) );183 assertThat( tests.get( 1 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );184 assertThat( tests.get( 1 ).hasError(), is( false ) );185 assertThat( tests.get( 2 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );186 assertThat( tests.get( 2 ).getName(), is( "testGreater" ) );187 assertThat( tests.get( 2 ).getFailureDetail(),188 is( "junit.framework.AssertionFailedError: >\n"189 + "\tat junit.framework.Assert.fail(Assert.java:47)\n"190 + "\tat wellFormedXmlFailures.TestSurefire3.testGreater(TestSurefire3.java:35)\n" ) );191 assertThat( tests.get( 2 ).getClassName(), is( "TestSurefire3" ) );192 assertThat( tests.get( 2 ).getTime(), is( 0f ) );193 assertThat( tests.get( 2 ).getFailureErrorLine(), is( "35" ) );194 assertThat( tests.get( 2 ).getFailureMessage(), is( ">" ) );195 assertThat( tests.get( 2 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testGreater" ) );196 assertThat( tests.get( 2 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );197 assertThat( tests.get( 2 ).hasError(), is( false ) );198 assertThat( tests.get( 3 ).getFullClassName(), is( "wellFormedXmlFailures.TestSurefire3" ) );199 assertThat( tests.get( 3 ).getName(), is( "testQuote" ) );200 assertThat( tests.get( 3 ).getFailureDetail(),201 is( "junit.framework.AssertionFailedError: \"\n"202 + "\tat junit.framework.Assert.fail(Assert.java:47)\n"203 + "\tat wellFormedXmlFailures.TestSurefire3.testQuote(TestSurefire3.java:25)\n" ) );204 assertThat( tests.get( 3 ).getClassName(), is( "TestSurefire3" ) );205 assertThat( tests.get( 3 ).getTime(), is( 0f ) );206 assertThat( tests.get( 3 ).getFailureErrorLine(), is( "25" ) );207 assertThat( tests.get( 3 ).getFailureMessage(), is( "\"" ) );208 assertThat( tests.get( 3 ).getFullName(), is( "wellFormedXmlFailures.TestSurefire3.testQuote" ) );209 assertThat( tests.get( 3 ).getFailureType(), is( "junit.framework.AssertionFailedError" ) );210 assertThat( tests.get( 3 ).hasError(), is( false ) );211 }212 @Test213 public void testParser()214 throws Exception215 {216 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );217 Collection<ReportTestSuite> oldResult = parser.parse(218 "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" );219 assertNotNull( oldResult );220 assertEquals( 1, oldResult.size() );221 ReportTestSuite next = oldResult.iterator().next();222 assertEquals( 2, next.getNumberOfTests() );223 }224 @Test225 public void successfulSurefireTestReport()226 throws Exception227 {228 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );229 File surefireReport = new File( "src/test/resources/junit-pathWithÃmlaut/TEST-umlautTest.BasicTest.xml" );230 assumeTrue( surefireReport.isFile() );231 Collection<ReportTestSuite> suites = parser.parse( surefireReport.getCanonicalPath() );232 assertNotNull( suites );233 assertEquals( 1, suites.size() );234 ReportTestSuite suite = suites.iterator().next();235 assertThat( suite.getNumberOfTests(), is( 1 ) );236 assertEquals( 1, suite.getNumberOfTests() );237 assertEquals( 0, suite.getNumberOfFlakes() );238 assertEquals( 0, suite.getNumberOfFailures() );239 assertEquals( 0, suite.getNumberOfErrors() );240 assertEquals( 0, suite.getNumberOfSkipped() );241 assertThat( suite.getTimeElapsed(), is( 0.002f ) );242 assertThat( suite.getFullClassName(), is( "umlautTest.BasicTest" ) );243 assertThat( suite.getPackageName(), is( "umlautTest" ) );244 assertThat( suite.getName(), is( "BasicTest" ) );245 ReportTestCase test = suite.getTestCases().iterator().next();246 assertTrue( test.isSuccessful() );247 assertNull( test.getFailureDetail() );248 assertNull( test.getFailureErrorLine() );249 assertNull( test.getFailureType() );250 assertThat( test.getTime(), is( 0.002f ) );251 assertThat( test.getFullClassName(), is( "umlautTest.BasicTest" ) );252 assertThat( test.getClassName(), is( "BasicTest" ) );253 assertThat( test.getName(), is( "testSetUp" ) );254 assertThat( test.getFullName(), is( "umlautTest.BasicTest.testSetUp" ) );255 }256 @Test257 public void testParserHitsFailsafeSummary()258 throws Exception259 {260 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );261 parser.parse( "src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml" );262 assertFalse( parser.isValid() );263 parser.parse(264 "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" );265 assertTrue( parser.isValid() );266 }267 @Test268 public void lastIndexOfPatternOfOrdinalTest()269 {270 final StringBuilder stackTrace = new StringBuilder(271 "\tat org.apache.Test.util(Test.java:60)\n"272 + "\tat org.apache.Test.test(Test.java:30)\n"273 + "\tat com.sun.Impl.xyz(Impl.java:258)\n" );274 int[] result = TestSuiteXmlParser.lastIndexOf( stackTrace, linePatterns );275 assertThat( result[0], is( 40 ) );276 assertThat( result[1], is( 0 ) );277 String errorLine = TestSuiteXmlParser.parseErrorLine( stackTrace, "org.apache.Test" );278 assertThat( errorLine, is( "30" ) );279 }280 @Test281 public void lastIndexOfPatternOfOrdinalTestWithCause()282 {283 final StringBuilder stackTrace = new StringBuilder(284 "\tat org.apache.Test.util(Test.java:60)\n"285 + "\tat org.apache.Test.test(Test.java:30)\n"286 + "\tat com.sun.Impl.xyz(Impl.java:258)\n"287 + "\tat Caused by: java.lang.IndexOutOfBoundsException\n"288 + "\tat org.apache.Test.util(Test.java:70)\n" );289 int[] result = TestSuiteXmlParser.lastIndexOf( stackTrace, linePatterns );290 assertThat( result[0], is( 40 ) );291 assertThat( result[1], is( 0 ) );292 String errorLine = TestSuiteXmlParser.parseErrorLine( stackTrace, "org.apache.Test" );293 assertThat( errorLine, is( "30" ) );294 }295 @Test296 public void lastIndexOfPatternOfEnclosedTest()297 {298 final StringBuilder source = new StringBuilder(299 "\tat org.apache.Test.util(Test.java:60)\n"300 + "\tat org.apache.Test$Nested.test(Test.java:30)\n"301 + "\tat com.sun.Impl.xyz(Impl.java:258)\n" );302 int[] result = TestSuiteXmlParser.lastIndexOf( source, linePatterns );303 assertThat( result[0], is( 40 ) );304 assertThat( result[1], is( 1 ) );305 String errorLine = TestSuiteXmlParser.parseErrorLine( source, "org.apache.Test$Nested" );306 assertThat( errorLine, is( "30" ) );307 }308 @Test309 public void lastIndexOfPatternOfEnclosedTestWithCause()310 {311 final StringBuilder source = new StringBuilder(312 "\tat org.apache.Test.util(Test.java:60)\n"313 + "\tat org.apache.Test$Nested.test(Test.java:30)\n"314 + "\tat com.sun.Impl.xyz(Impl.java:258)\n"315 + "\tat Caused by: java.lang.IndexOutOfBoundsException\n"316 + "\tat org.apache.Test$Nested.util(Test.java:70)\n" );317 int[] result = TestSuiteXmlParser.lastIndexOf( source, linePatterns );318 assertThat( result[0], is( 40 ) );319 assertThat( result[1], is( 1 ) );320 String errorLine = TestSuiteXmlParser.parseErrorLine( source, "org.apache.Test$Nested" );321 assertThat( errorLine, is( "30" ) );322 }323 @Test324 public void shouldParserEverythingInOrdinalTest()325 throws Exception326 {327 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );328 List<ReportTestSuite> tests =329 parser.parse( "src/test/resources/fixture/testsuitexmlparser/TEST-surefire.MyTest.xml" );330 assertTrue( parser.isValid() );331 assertThat( tests.size(), is( 1 ) );332 assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );333 assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );334 assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );335 assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );336 assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );337 assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );338 assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );339 assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );340 assertFalse( tests.get( 0 ).getTestCases().get( 0 ).isSuccessful() );341 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "13" ) );342 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(), is( "java.lang.RuntimeException" ) );343 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );344 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest" ) );345 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "test" ) );346 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest.test" ) );347 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0.1f ) );348 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(), is( "this is different message" ) );349 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),350 is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"351 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"352 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"353 + "\tat surefire.MyTest.test(MyTest.java:13)\n"354 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"355 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"356 + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"357 + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"358 + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"359 + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"360 + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"361 + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"362 + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"363 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"364 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"365 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"366 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"367 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"368 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"369 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"370 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"371 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"372 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"373 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"374 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"375 + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"376 + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"377 + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"378 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"379 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"380 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"381 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"382 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"383 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" ) );384 assertThat( tests.get( 0 ).getTestCases().get( 0 ).hasError(), is( true ) );385 }386 @Test387 public void shouldParserEverythingInEnclosedTest()388 throws Exception389 {390 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );391 List<ReportTestSuite> tests =392 parser.parse( "src/test/resources/fixture/testsuitexmlparser/TEST-surefire.MyTest-enclosed.xml" );393 assertTrue( parser.isValid() );394 assertThat( tests.size(), is( 1 ) );395 assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );396 assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );397 assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );398 assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );399 assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );400 assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );401 assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );402 assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );403 assertFalse( tests.get( 0 ).getTestCases().get( 0 ).isSuccessful() );404 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "45" ) );405 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),406 is( "java.lang.RuntimeException" ) );407 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );408 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest$A" ) );409 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "t" ) );410 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest$A.t" ) );411 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );412 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),413 is( "java.lang.IndexOutOfBoundsException" ) );414 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),415 is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"416 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"417 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"418 + "\tat surefire.MyTest.access$200(MyTest.java:9)\n"419 + "\tat surefire.MyTest$A.t(MyTest.java:45)\n"420 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"421 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"422 + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"423 + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"424 + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"425 + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"426 + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"427 + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"428 + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"429 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"430 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"431 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"432 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"433 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"434 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"435 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"436 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"437 + "\tat org.junit.runners.Suite.runChild(Suite.java:128)\n"438 + "\tat org.junit.runners.Suite.runChild(Suite.java:27)\n"439 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"440 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"441 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"442 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"443 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"444 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"445 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"446 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"447 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"448 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"449 + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"450 + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"451 + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"452 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"453 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"454 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"455 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"456 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"457 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)\n" ) );458 assertThat( tests.get( 0 ).getTestCases().get( 0 ).hasError(), is( true ) );459 }460 @Test461 public void shouldParserEverythingInEnclosedTrimStackTraceTest()462 throws Exception463 {464 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );465 List<ReportTestSuite> tests = parser.parse( "src/test/resources/fixture/testsuitexmlparser/"466 + "TEST-surefire.MyTest-enclosed-trimStackTrace.xml" );467 assertTrue( parser.isValid() );468 assertThat( tests.size(), is( 1 ) );469 assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );470 assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );471 assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );472 assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );473 assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );474 assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );475 assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );476 assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );477 assertFalse( tests.get( 0 ).getTestCases().get( 0 ).isSuccessful() );478 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "45" ) );479 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),480 is( "java.lang.RuntimeException" ) );481 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest$A" ) );482 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest$A" ) );483 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "t" ) );484 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest$A.t" ) );485 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );486 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),487 is( "java.lang.IndexOutOfBoundsException" ) );488 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),489 is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"490 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"491 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"492 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"493 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"494 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)\n"495 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"496 + "\tat surefire.MyTest.access$200(MyTest.java:9)\n"497 + "\tat surefire.MyTest$A.t(MyTest.java:45)\n" ) );498 assertThat( tests.get( 0 ).getTestCases().get( 0 ).hasError(), is( true ) );499 }500 @Test501 public void shouldParserEverythingInNestedClassTest()502 throws Exception503 {504 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );505 List<ReportTestSuite> tests = parser.parse( "src/test/resources/fixture/testsuitexmlparser/"506 + "TEST-surefire.MyTest-nestedClass.xml" );507 assertTrue( parser.isValid() );508 assertThat( tests.size(), is( 1 ) );509 assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );510 assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );511 assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );512 assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );513 assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );514 assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );515 assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );516 assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );517 assertFalse( tests.get( 0 ).getTestCases().get( 0 ).isSuccessful() );518 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "13" ) );519 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),520 is( "java.lang.RuntimeException" ) );521 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );522 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest" ) );523 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "test" ) );524 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest.test" ) );525 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );526 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),527 is( "java.lang.IndexOutOfBoundsException" ) );528 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),529 is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"530 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"531 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"532 + "\tat surefire.MyTest.test(MyTest.java:13)\n"533 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"534 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"535 + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"536 + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"537 + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"538 + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"539 + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"540 + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"541 + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"542 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"543 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"544 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"545 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"546 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"547 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"548 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"549 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"550 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"551 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"552 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"553 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"554 + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"555 + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"556 + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"557 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"558 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"559 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"560 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"561 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"562 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" ) );563 assertThat( tests.get( 0 ).getTestCases().get( 0 ).hasError(), is( true ) );564 }565 @Test566 public void shouldParserEverythingInNestedClassTrimStackTraceTest()567 throws Exception568 {569 TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger );570 List<ReportTestSuite> tests = parser.parse( "src/test/resources/fixture/testsuitexmlparser/"571 + "TEST-surefire.MyTest-nestedClass-trimStackTrace.xml" );572 assertTrue( parser.isValid() );573 assertThat( tests.size(), is( 1 ) );574 assertThat( tests.get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );575 assertThat( tests.get( 0 ).getNumberOfErrors(), is( 1 ) );576 assertThat( tests.get( 0 ).getNumberOfFlakes(), is( 0 ) );577 assertThat( tests.get( 0 ).getNumberOfSkipped(), is( 0 ) );578 assertThat( tests.get( 0 ).getNumberOfFailures(), is( 0 ) );579 assertThat( tests.get( 0 ).getPackageName(), is( "surefire" ) );580 assertThat( tests.get( 0 ).getNumberOfTests(), is( 1 ) );581 assertThat( tests.get( 0 ).getTestCases().size(), is( 1 ) );582 assertFalse( tests.get( 0 ).getTestCases().get( 0 ).isSuccessful() );583 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureErrorLine(), is( "13" ) );584 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureType(),585 is( "java.lang.RuntimeException" ) );586 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullClassName(), is( "surefire.MyTest" ) );587 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getClassName(), is( "MyTest" ) );588 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getName(), is( "test" ) );589 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFullName(), is( "surefire.MyTest.test" ) );590 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getTime(), is( 0f ) );591 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureMessage(),592 is( "java.lang.IndexOutOfBoundsException" ) );593 assertThat( tests.get( 0 ).getTestCases().get( 0 ).getFailureDetail(),594 is( "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"595 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"596 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"597 + "\tat surefire.MyTest.test(MyTest.java:13)\n"598 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"599 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"600 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"601 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"602 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"...
Source:TestResultParserTest.java
...20 assertFieldsNotNull(testResult);21 }22 assertEquals("Result status should be PASSED", RunResult.Status.PASSED, result.status);23 assertEquals(24 "Test name was wrong", "ArithTest testAdd", result.testResults.get(0).getName());25 }26 @Test27 @SuppressWarnings("checkstyle:linelength")28 public void testParseTestJson() {29 String json =30 "[{\"className\"=>\"ArithTest\","31 + " \"methodName\"=>\"testAdd\","32 + " \"pointNames\"=>[\"arith-funcs\"],"33 + " \"status\"=>\"PASSED\"},"34 + " {\"className\"=>\"ArithTest\","35 + " \"methodName\"=>\"testSub\","36 + " \"pointNames\"=>[\"arith-funcs\"],"37 + " \"message\"=>\"expected:<-1> but was:<0>\","38 + " \"exception\"=>"39 + " {\"className\"=>\"java.lang.AssertionError\","40 + " \"message\"=>\"expected:<-1> but was:<0>\","41 + " \"stackTrace\"=>"42 + " [{\"declaringClass\"=>\"org.junit.Assert\","43 + " \"methodName\"=>\"fail\","44 + " \"fileName\"=>\"Assert.java\","45 + " \"lineNumber\"=>88},"46 + " {\"declaringClass\"=>\"org.junit.Assert\","47 + " \"methodName\"=>\"failNotEquals\","48 + " \"fileName\"=>\"Assert.java\","49 + " \"lineNumber\"=>743},"50 + " {\"declaringClass\"=>\"org.junit.Assert\","51 + " \"methodName\"=>\"assertEquals\","52 + " \"fileName\"=>\"Assert.java\","53 + " \"lineNumber\"=>118},"54 + " {\"declaringClass\"=>\"org.junit.Assert\","55 + " \"methodName\"=>\"assertEquals\","56 + " \"fileName\"=>\"Assert.java\","57 + " \"lineNumber\"=>555},"58 + " {\"declaringClass\"=>\"org.junit.Assert\","59 + " \"methodName\"=>\"assertEquals\","60 + " \"fileName\"=>\"Assert.java\","61 + " \"lineNumber\"=>542},"62 + " {\"declaringClass\"=>\"ArithTest\","63 + " \"methodName\"=>\"testSub\","64 + " \"fileName\"=>\"ArithTest.java\","65 + " \"lineNumber\"=>16},"66 + " {\"declaringClass\"=>\"sun.reflect.NativeMethodAccessorImpl\","67 + " \"methodName\"=>\"invoke0\","68 + " \"fileName\"=>\"NativeMethodAccessorImpl.java\","69 + " \"lineNumber\"=>-2},"70 + " {\"declaringClass\"=>\"sun.reflect.NativeMethodAccessorImpl\","71 + " \"methodName\"=>\"invoke\","72 + " \"fileName\"=>\"NativeMethodAccessorImpl.java\","73 + " \"lineNumber\"=>62},"74 + " {\"declaringClass\"=>\"sun.reflect.DelegatingMethodAccessorImpl\","75 + " \"methodName\"=>\"invoke\","76 + " \"fileName\"=>\"DelegatingMethodAccessorImpl.java\","77 + " \"lineNumber\"=>43},"78 + " {\"declaringClass\"=>\"java.lang.reflect.Method\","79 + " \"methodName\"=>\"invoke\","80 + " \"fileName\"=>\"Method.java\","81 + " \"lineNumber\"=>483},"82 + " {\"declaringClass\"=>\"org.junit.runners.model."83 + "FrameworkMethod$1\","84 + " \"methodName\"=>\"runReflectiveCall\","85 + " \"fileName\"=>\"FrameworkMethod.java\","86 + " \"lineNumber\"=>47},"87 + " {\"declaringClass\"=>\"org.junit.internal.runners.model."88 + "ReflectiveCallable\","89 + " \"methodName\"=>\"run\","90 + " \"fileName\"=>\"ReflectiveCallable.java\","91 + " \"lineNumber\"=>12},"92 + " {\"declaringClass\"=>\"org.junit.runners.model.FrameworkMethod\","93 + " \"methodName\"=>\"invokeExplosively\","94 + " \"fileName\"=>\"FrameworkMethod.java\","95 + " \"lineNumber\"=>44},"96 + " {\"declaringClass\"=>\"org.junit.internal.runners.statements."97 + "InvokeMethod\","98 + " \"methodName\"=>\"evaluate\","99 + " \"fileName\"=>\"InvokeMethod.java\","100 + " \"lineNumber\"=>17},"101 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","102 + " \"methodName\"=>\"runLeaf\","103 + " \"fileName\"=>\"ParentRunner.java\","104 + " \"lineNumber\"=>271},"105 + " {\"declaringClass\"=>\"org.junit.runners.BlockJUnit4ClassRunner\","106 + " \"methodName\"=>\"runChild\","107 + " \"fileName\"=>\"BlockJUnit4ClassRunner.java\","108 + " \"lineNumber\"=>70},"109 + " {\"declaringClass\"=>\"org.junit.runners.BlockJUnit4ClassRunner\","110 + " \"methodName\"=>\"runChild\","111 + " \"fileName\"=>\"BlockJUnit4ClassRunner.java\","112 + " \"lineNumber\"=>50},"113 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$3\","114 + " \"methodName\"=>\"run\","115 + " \"fileName\"=>\"ParentRunner.java\","116 + " \"lineNumber\"=>238},"117 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$1\","118 + " \"methodName\"=>\"schedule\","119 + " \"fileName\"=>\"ParentRunner.java\","120 + " \"lineNumber\"=>63},"121 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","122 + " \"methodName\"=>\"runChildren\","123 + " \"fileName\"=>\"ParentRunner.java\","124 + " \"lineNumber\"=>236},"125 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","126 + " \"methodName\"=>\"access$000\","127 + " \"fileName\"=>\"ParentRunner.java\","128 + " \"lineNumber\"=>53},"129 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$2\","130 + " \"methodName\"=>\"evaluate\","131 + " \"fileName\"=>\"ParentRunner.java\","132 + " \"lineNumber\"=>229},"133 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","134 + " \"methodName\"=>\"run\","135 + " \"fileName\"=>\"ParentRunner.java\","136 + " \"lineNumber\"=>309},"137 + " {\"declaringClass\"=>"138 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","139 + " \"methodName\"=>\"runTestCase\","140 + " \"fileName\"=>\"TestRunner.java\","141 + " \"lineNumber\"=>134},"142 + " {\"declaringClass\"=>"143 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","144 + " \"methodName\"=>\"doRun\","145 + " \"fileName\"=>\"TestRunner.java\","146 + " \"lineNumber\"=>89},"147 + " {\"declaringClass\"=>"148 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","149 + " \"methodName\"=>\"run\","150 + " \"fileName\"=>\"TestRunner.java\","151 + " \"lineNumber\"=>70},"152 + " {\"declaringClass\"=>\"java.lang.Thread\","153 + " \"methodName\"=>\"run\","154 + " \"fileName\"=>\"Thread.java\","155 + " \"lineNumber\"=>745}]},"156 + " \"status\"=>\"FAILED\"},"157 + " {\"className\"=>\"ArithTest\","158 + " \"methodName\"=>\"testMul\","159 + " \"pointNames\"=>[\"arith-funcs\"],"160 + " \"message\"=>\"expected:<12> but was:<0>\","161 + " \"exception\"=>"162 + " {\"className\"=>\"java.lang.AssertionError\","163 + " \"message\"=>\"expected:<12> but was:<0>\","164 + " \"stackTrace\"=>"165 + " [{\"declaringClass\"=>\"org.junit.Assert\","166 + " \"methodName\"=>\"fail\","167 + " \"fileName\"=>\"Assert.java\","168 + " \"lineNumber\"=>88},"169 + " {\"declaringClass\"=>\"org.junit.Assert\","170 + " \"methodName\"=>\"failNotEquals\","171 + " \"fileName\"=>\"Assert.java\","172 + " \"lineNumber\"=>743},"173 + " {\"declaringClass\"=>\"org.junit.Assert\","174 + " \"methodName\"=>\"assertEquals\","175 + " \"fileName\"=>\"Assert.java\","176 + " \"lineNumber\"=>118},"177 + " {\"declaringClass\"=>\"org.junit.Assert\","178 + " \"methodName\"=>\"assertEquals\","179 + " \"fileName\"=>\"Assert.java\","180 + " \"lineNumber\"=>555},"181 + " {\"declaringClass\"=>\"org.junit.Assert\","182 + " \"methodName\"=>\"assertEquals\","183 + " \"fileName\"=>\"Assert.java\","184 + " \"lineNumber\"=>542},"185 + " {\"declaringClass\"=>\"ArithTest\","186 + " \"methodName\"=>\"testMul\","187 + " \"fileName\"=>\"ArithTest.java\","188 + " \"lineNumber\"=>22},"189 + " {\"declaringClass\"=>\"sun.reflect.NativeMethodAccessorImpl\","190 + " \"methodName\"=>\"invoke0\","191 + " \"fileName\"=>\"NativeMethodAccessorImpl.java\","192 + " \"lineNumber\"=>-2},"193 + " {\"declaringClass\"=>\"sun.reflect.NativeMethodAccessorImpl\","194 + " \"methodName\"=>\"invoke\","195 + " \"fileName\"=>\"NativeMethodAccessorImpl.java\","196 + " \"lineNumber\"=>62},"197 + " {\"declaringClass\"=>\"sun.reflect.DelegatingMethodAccessorImpl\","198 + " \"methodName\"=>\"invoke\","199 + " \"fileName\"=>\"DelegatingMethodAccessorImpl.java\","200 + " \"lineNumber\"=>43},"201 + " {\"declaringClass\"=>\"java.lang.reflect.Method\","202 + " \"methodName\"=>\"invoke\","203 + " \"fileName\"=>\"Method.java\","204 + " \"lineNumber\"=>483},"205 + " {\"declaringClass\"=>\"org.junit.runners.model."206 + "FrameworkMethod$1\","207 + " \"methodName\"=>\"runReflectiveCall\","208 + " \"fileName\"=>\"FrameworkMethod.java\","209 + " \"lineNumber\"=>47},"210 + " {\"declaringClass\"=>\"org.junit.internal.runners.model."211 + "ReflectiveCallable\","212 + " \"methodName\"=>\"run\","213 + " \"fileName\"=>\"ReflectiveCallable.java\","214 + " \"lineNumber\"=>12},"215 + " {\"declaringClass\"=>\"org.junit.runners.model.FrameworkMethod"216 + "\","217 + " \"methodName\"=>\"invokeExplosively\","218 + " \"fileName\"=>\"FrameworkMethod.java\","219 + " \"lineNumber\"=>44},"220 + " {\"declaringClass\"=>\"org.junit.internal.runners.statements."221 + "InvokeMethod\","222 + " \"methodName\"=>\"evaluate\","223 + " \"fileName\"=>\"InvokeMethod.java\","224 + " \"lineNumber\"=>17},"225 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","226 + " \"methodName\"=>\"runLeaf\","227 + " \"fileName\"=>\"ParentRunner.java\","228 + " \"lineNumber\"=>271},"229 + " {\"declaringClass\"=>\"org.junit.runners.BlockJUnit4ClassRunner\","230 + " \"methodName\"=>\"runChild\","231 + " \"fileName\"=>\"BlockJUnit4ClassRunner.java\","232 + " \"lineNumber\"=>70},"233 + " {\"declaringClass\"=>\"org.junit.runners.BlockJUnit4ClassRunner\","234 + " \"methodName\"=>\"runChild\","235 + " \"fileName\"=>\"BlockJUnit4ClassRunner.java\","236 + " \"lineNumber\"=>50},"237 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$3\","238 + " \"methodName\"=>\"run\","239 + " \"fileName\"=>\"ParentRunner.java\","240 + " \"lineNumber\"=>238},"241 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$1\","242 + " \"methodName\"=>\"schedule\","243 + " \"fileName\"=>\"ParentRunner.java\","244 + " \"lineNumber\"=>63},"245 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","246 + " \"methodName\"=>\"runChildren\","247 + " \"fileName\"=>\"ParentRunner.java\","248 + " \"lineNumber\"=>236},"249 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","250 + " \"methodName\"=>\"access$000\","251 + " \"fileName\"=>\"ParentRunner.java\","252 + " \"lineNumber\"=>53},"253 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$2\","254 + " \"methodName\"=>\"evaluate\","255 + " \"fileName\"=>\"ParentRunner.java\","256 + " \"lineNumber\"=>229},"257 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","258 + " \"methodName\"=>\"run\","259 + " \"fileName\"=>\"ParentRunner.java\","260 + " \"lineNumber\"=>309},"261 + " {\"declaringClass\"=>"262 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","263 + " \"methodName\"=>\"runTestCase\","264 + " \"fileName\"=>\"TestRunner.java\","265 + " \"lineNumber\"=>134},"266 + " {\"declaringClass\"=>"267 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","268 + " \"methodName\"=>\"doRun\","269 + " \"fileName\"=>\"TestRunner.java\","270 + " \"lineNumber\"=>89},"271 + " {\"declaringClass\"=>"272 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","273 + " \"methodName\"=>\"run\","274 + " \"fileName\"=>\"TestRunner.java\","275 + " \"lineNumber\"=>70},"276 + " {\"declaringClass\"=>\"java.lang.Thread\","277 + " \"methodName\"=>\"run\","278 + " \"fileName\"=>\"Thread.java\","279 + " \"lineNumber\"=>745}]},"280 + " \"status\"=>\"FAILED\"},"281 + " {\"className\"=>\"ArithTest\","282 + " \"methodName\"=>\"testDiv\","283 + " \"pointNames\"=>[\"arith-funcs\"],"284 + " \"message\"=>\"expected:<3> but was:<0>\","285 + " \"exception\"=>"286 + " {\"className\"=>\"java.lang.AssertionError\","287 + " \"message\"=>\"expected:<3> but was:<0>\","288 + " \"stackTrace\"=>"289 + " [{\"declaringClass\"=>\"org.junit.Assert\","290 + " \"methodName\"=>\"fail\","291 + " \"fileName\"=>\"Assert.java\","292 + " \"lineNumber\"=>88},"293 + " {\"declaringClass\"=>\"org.junit.Assert\","294 + " \"methodName\"=>\"failNotEquals\","295 + " \"fileName\"=>\"Assert.java\","296 + " \"lineNumber\"=>743},"297 + " {\"declaringClass\"=>\"org.junit.Assert\","298 + " \"methodName\"=>\"assertEquals\","299 + " \"fileName\"=>\"Assert.java\","300 + " \"lineNumber\"=>118},"301 + " {\"declaringClass\"=>\"org.junit.Assert\","302 + " \"methodName\"=>\"assertEquals\","303 + " \"fileName\"=>\"Assert.java\","304 + " \"lineNumber\"=>555},"305 + " {\"declaringClass\"=>\"org.junit.Assert\","306 + " \"methodName\"=>\"assertEquals\","307 + " \"fileName\"=>\"Assert.java\","308 + " \"lineNumber\"=>542},"309 + " {\"declaringClass\"=>\"ArithTest\","310 + " \"methodName\"=>\"testDiv\","311 + " \"fileName\"=>\"ArithTest.java\","312 + " \"lineNumber\"=>29},"313 + " {\"declaringClass\"=>\"sun.reflect.NativeMethodAccessorImpl\","314 + " \"methodName\"=>\"invoke0\","315 + " \"fileName\"=>\"NativeMethodAccessorImpl.java\","316 + " \"lineNumber\"=>-2},"317 + " {\"declaringClass\"=>\"sun.reflect.NativeMethodAccessorImpl\","318 + " \"methodName\"=>\"invoke\","319 + " \"fileName\"=>\"NativeMethodAccessorImpl.java\","320 + " \"lineNumber\"=>62},"321 + " {\"declaringClass\"=>\"sun.reflect.DelegatingMethodAccessorImpl\","322 + " \"methodName\"=>\"invoke\","323 + " \"fileName\"=>\"DelegatingMethodAccessorImpl.java\","324 + " \"lineNumber\"=>43},"325 + " {\"declaringClass\"=>\"java.lang.reflect.Method\","326 + " \"methodName\"=>\"invoke\","327 + " \"fileName\"=>\"Method.java\","328 + " \"lineNumber\"=>483},"329 + " {\"declaringClass\"=>\"org.junit.runners.model."330 + "FrameworkMethod$1\","331 + " \"methodName\"=>\"runReflectiveCall\","332 + " \"fileName\"=>\"FrameworkMethod.java\","333 + " \"lineNumber\"=>47},"334 + " {\"declaringClass\"=>\"org.junit.internal.runners.model."335 + "ReflectiveCallable\","336 + " \"methodName\"=>\"run\","337 + " \"fileName\"=>\"ReflectiveCallable.java\","338 + " \"lineNumber\"=>12},"339 + " {\"declaringClass\"=>\"org.junit.runners.model.FrameworkMethod\","340 + " \"methodName\"=>\"invokeExplosively\","341 + " \"fileName\"=>\"FrameworkMethod.java\","342 + " \"lineNumber\"=>44},"343 + " {\"declaringClass\"=>\"org.junit.internal.runners.statements."344 + "InvokeMethod\","345 + " \"methodName\"=>\"evaluate\","346 + " \"fileName\"=>\"InvokeMethod.java\","347 + " \"lineNumber\"=>17},"348 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","349 + " \"methodName\"=>\"runLeaf\","350 + " \"fileName\"=>\"ParentRunner.java\","351 + " \"lineNumber\"=>271},"352 + " {\"declaringClass\"=>\"org.junit.runners.BlockJUnit4ClassRunner\","353 + " \"methodName\"=>\"runChild\","354 + " \"fileName\"=>\"BlockJUnit4ClassRunner.java\","355 + " \"lineNumber\"=>70},"356 + " {\"declaringClass\"=>\"org.junit.runners.BlockJUnit4ClassRunner\","357 + " \"methodName\"=>\"runChild\","358 + " \"fileName\"=>\"BlockJUnit4ClassRunner.java\","359 + " \"lineNumber\"=>50},"360 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$3\","361 + " \"methodName\"=>\"run\","362 + " \"fileName\"=>\"ParentRunner.java\","363 + " \"lineNumber\"=>238},"364 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$1\","365 + " \"methodName\"=>\"schedule\","366 + " \"fileName\"=>\"ParentRunner.java\","367 + " \"lineNumber\"=>63},"368 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","369 + " \"methodName\"=>\"runChildren\","370 + " \"fileName\"=>\"ParentRunner.java\","371 + " \"lineNumber\"=>236},"372 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","373 + " \"methodName\"=>\"access$000\","374 + " \"fileName\"=>\"ParentRunner.java\","375 + " \"lineNumber\"=>53},"376 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner$2\","377 + " \"methodName\"=>\"evaluate\","378 + " \"fileName\"=>\"ParentRunner.java\","379 + " \"lineNumber\"=>229},"380 + " {\"declaringClass\"=>\"org.junit.runners.ParentRunner\","381 + " \"methodName\"=>\"run\","382 + " \"fileName\"=>\"ParentRunner.java\","383 + " \"lineNumber\"=>309},"384 + " {\"declaringClass\"=>"385 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","386 + " \"methodName\"=>\"runTestCase\","387 + " \"fileName\"=>\"TestRunner.java\","388 + " \"lineNumber\"=>134},"389 + " {\"declaringClass\"=>"390 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","391 + " \"methodName\"=>\"doRun\","392 + " \"fileName\"=>\"TestRunner.java\","393 + " \"lineNumber\"=>89},"394 + " {\"declaringClass\"=>"395 + " \"fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable\","396 + " \"methodName\"=>\"run\","397 + " \"fileName\"=>\"TestRunner.java\","398 + " \"lineNumber\"=>70},"399 + " {\"declaringClass\"=>\"java.lang.Thread\","400 + " \"methodName\"=>\"run\","401 + " \"fileName\"=>\"Thread.java\","402 + " \"lineNumber\"=>745}]},"403 + " \"status\"=>\"FAILED\"}]";404 ;405 RunResult result = parser.parseTestResult(json, new byte[0], new byte[0]);406 assertNotNull(result);407 for (TestResult testResult : result.testResults) {408 assertFieldsNotNull(testResult);409 }410 assertEquals("There should be 4 test results in the result", 4, result.testResults.size());411 TestResult testResult = result.testResults.get(0);412 assertEquals("ArithTest testAdd", testResult.getName());413 assertTrue("ArithTest testAdd passed should be true", testResult.isSuccessful());414 }415 private void assertFieldsNotNull(TestResult testResult) {416 assertNotNull(testResult.getMessage());417 assertNotNull(testResult.getDetailedMessage());418 assertNotNull(testResult.getException());419 assertNotNull(testResult.getName());420 assertNotNull(testResult.getValgrindFailed());421 }422}...
Source:SQLPluginTest.java
...24 @Test25 public void getDdlType() {26 IType result = TypeSystem.getByFullNameIfValid("gosu.db.foo.Users");27 assertNotNull(result);28 assertEquals("gosu.db.foo.Users", result.getName());29 }30 @Test31 public void getSQLType() {32 IType result = TypeSystem.getByFullNameIfValid("gosu.db.foo.MyQuery");33 assertNotNull(result);34 assertEquals("gosu.db.foo.MyQuery", result.getName());35 }36 @Test37 public void getTablesFromSelect() {38 IType result = TypeSystem.getByFullNameIfValid("gosu.db.foo.MyQuery.Contact");39 assertNull(result);40 }41 @Test42 public void getTypeExplicitly() {43 IType result = TypeSystem.getByFullNameIfValid("gosu.db.foo.Users.Contact");44 assertNotNull(result);45 assertEquals("gosu.db.foo.Users.Contact", result.getName());46 }47 @Test48 public void getNamesFromSQL() {49 ISQLQueryType result = (ISQLQueryType) TypeSystem.getByFullNameIfValid("gosu.db.foo.MyQuery");50 assertNotNull(result);51 assertEquals("gosu.db.foo.MyQuery", result.getName());52 assertEquals("gosu.db.foo", result.getNamespace());53 assertEquals("MyQuery", result.getRelativeName());54 }55 @Test56 public void getNonExistantType() {57 IType result = TypeSystem.getByFullNameIfValid("gosu.db.foo.Unknown.DoesNotExist");58 assertNull(result);59 }60 @Test61 public void testSQLExecute() {62 ISQLQueryType result = (ISQLQueryType) TypeSystem.getByFullNameIfValid("gosu.db.foo.MyQuery");63 assertNotNull(result);64 SQLBaseTypeInfo ti = (SQLBaseTypeInfo) result.getTypeInfo();65 IMethodInfo execute = ti.getMethod("execute", JavaTypes.STRING());66 assertNotNull(execute);67 }68 @Test69 public void testSQLResult() {70 TypeSystem.getByFullNameIfValid("gosu.db.foo.Users");71 ISQLQueryType result = (ISQLQueryType) TypeSystem.getByFullNameIfValid("gosu.db.foo.MyQuery2");72 assertNotNull(result);73 SQLBaseTypeInfo ti = (SQLBaseTypeInfo) result.getTypeInfo();74 IMethodInfo execute = ti.getMethod("execute");75 assertNotNull(execute);76 IType[] typeParameters = execute.getReturnType().getTypeParameters();77 ITypeInfo typeInfo = typeParameters[0].getTypeInfo();78 int a = 0;79 }80 @Test81 public void oneSourceWithMultipleTypes() {82 IType result = TypeSystem.getByFullNameIfValid("gosu.db.foo.Vehicles.Car");83 assertNotNull(result);84 assertEquals("gosu.db.foo.Vehicles.Car", result.getName());85 result = TypeSystem.getByFullNameIfValid("gosu.db.foo.Vehicles.Motorcycle");86 assertNotNull(result);87 assertEquals("gosu.db.foo.Vehicles.Motorcycle", result.getName());88 }89 @Test90 public void getColumnDefs() {91 ISQLTableType result = (ISQLTableType) TypeSystem.getByFullNameIfValid("gosu.db.foo.Users.Contact");92 assertNotNull(result);93 List<ColumnDefinition> colDefs = result.getColumnDefinitions();94 assertNotNull(colDefs);95 Set<String> expectedColumnNames = Stream.of("UserId", "LastName", "FirstName", "Age").collect(Collectors.toSet());96 Set<String> actualColumnNames = colDefs.stream().map(ColumnDefinition::getColumnName).collect(Collectors.toSet());97 assertEquals(expectedColumnNames, actualColumnNames);98 //TODO check columndef positions in the source files99 }100 public void getTypeInfo() {101 ISQLTableType result = (ISQLTableType) TypeSystem.getByFullNameIfValid("gosu.db.foo.Users.Contact");102 assertNotNull(result);103 assertEquals("gosu.db.foo.Users.Contact", result.getName());104 assertEquals("gosu.db.foo.Users", result.getNamespace());105 assertEquals("Contact", result.getRelativeName());106 SQLBaseTypeInfo ti = (SQLBaseTypeInfo) result.getTypeInfo();107 assertEquals("Contact", ti.getName());108 //make a set of expected Name/IJavaType pairs109 Set<String> expectedPropertyNames = Stream.of("UserId", "LastName", "FirstName", "Age").collect(Collectors.toSet());110 Map<String, IJavaType> expectedPropertyNameAndType = new HashMap<>(expectedPropertyNames.size());111 expectedPropertyNameAndType.put("UserId", JavaTypes.pINT());112 expectedPropertyNameAndType.put("LastName", JavaTypes.STRING());113 expectedPropertyNameAndType.put("FirstName", JavaTypes.STRING());114 expectedPropertyNameAndType.put("Age", JavaTypes.pINT());115 //number of properties is what we expect116 assertEquals(expectedPropertyNameAndType.size(), ti.getProperties().size()); //TODO domain logic breaks this test117 //each property name has a match in the map, and the type is identical118 for(IPropertyInfo actualProp : ti.getProperties()) {119 IJavaType expectedType = expectedPropertyNameAndType.get(actualProp.getName());120 assertNotNull("expectedType was null, meaning the actualProp's name was not found in the map", expectedType);121 assertSame(expectedType, actualProp.getFeatureType());122 }123 }124 @Test125 public void getMethodInfo() {126 ISQLTableType result = (ISQLTableType) TypeSystem.getByFullNameIfValid("gosu.db.foo.Users.Contact");127 assertNotNull(result);128 assertEquals("gosu.db.foo.Users.Contact", result.getName());129 assertEquals("gosu.db.foo.Users", result.getNamespace());130 assertEquals("Contact", result.getRelativeName());131 SQLBaseTypeInfo ti = (SQLBaseTypeInfo) result.getTypeInfo();132 assertEquals("Contact", ti.getName());133 IMethodInfo findByAge = ti.getMethod("findByAge", JavaTypes.pINT());134 assertNotNull(findByAge);135 assertEquals("gosu.db.foo.Users.Contact", findByAge.getReturnType().getName()); //returns single Contact136 IMethodInfo findAllByAge = ti.getMethod("findAllByAge", JavaTypes.pINT());137 assertNotNull(findAllByAge);138 assertEquals("java.lang.Iterable<gosu.db.foo.Users.Contact>", findAllByAge.getReturnType().getName()); //returns Iterable of Contacts //TODO KB139 IMethodInfo findByAgeWithWrongSignature = ti.getMethod("findByAge", JavaTypes.STRING());140 assertNull(findByAgeWithWrongSignature);141 IMethodInfo unknownMethodWithNoArgs = ti.getMethod("findSomethingWhichDoesNotExist");142 assertNull(unknownMethodWithNoArgs);143 }144 @Test145 @Ignore146 public void getRawSQL() {147 ISQLDdlType result = (ISQLDdlType) TypeSystem.getByFullNameIfValid("gosu.db.foo.Users");148 assertNotNull(result);149 assertEquals("gosu.db.foo.Users", result.getName());150 String expectedSource = "CREATE TABLE CONTACTS (\n" +151 " UserId int,\n" +152 " FirstName nchar(50),\n" +153 " LastName nchar(50),\n" +154 " Age int\n" +155 " -- TODO add Gender\n" +156 ");";157 String actualSource = null;158 try {159 actualSource = result.getSqlSource();160 System.out.println(actualSource);161 } catch(IOException e) {162 e.printStackTrace();163 fail();164 }165 assertEquals(expectedSource, actualSource);166 SQLBaseTypeInfo ti = (SQLBaseTypeInfo) result.getTypeInfo();167 assertEquals("Users", ti.getName());168 IPropertyInfo readOnlySqlSourceProperty = ti.getProperty("SqlSource");169 assertNotNull(readOnlySqlSourceProperty);170 assertTrue(readOnlySqlSourceProperty.isReadable());171 assertFalse(readOnlySqlSourceProperty.isWritable());172 assertEquals(expectedSource, readOnlySqlSourceProperty.getAccessor().getValue(null));173 }174 @Test175 // @Ignore("Fails individually on result != null, but succeeds in the whole test")176 public void getResultInfo() throws InterruptedException{177 TypeSystem.getByFullName("gosu.db.foo.Users");178 ISQLQueryType query = (ISQLQueryType)TypeSystem.getByFullName("gosu.db.foo.MyQuery2");179 query.getTypeInfo();180 ISQLQueryResultType expectedResult = query.getResultType();181 assertNotNull(expectedResult);182 ISQLQueryResultType result = (ISQLQueryResultType) TypeSystem.getByFullName("gosu.db.foo.MyQuery2Result");183 assertEquals(result.getTable().getTable().getTypeName(), "Contact");184 }185 @Test186 public void getSynthesizedMethod() {187 ISQLTableType result = (ISQLTableType) TypeSystem.getByFullNameIfValid("gosu.db.foo.Bars.Baz");188 assertNotNull(result);189 assertEquals("gosu.db.foo.Bars.Baz", result.getName());190 assertEquals("gosu.db.foo.Bars", result.getNamespace());191 assertEquals("Baz", result.getRelativeName());192 SQLTableTypeInfo ti = (SQLTableTypeInfo) result.getTypeInfo();193 assertEquals("Baz", ti.getName());194 IMethodInfo domainLogicMethod = ti.getMethod("sayHi", JavaTypes.STRING());195 assertNotNull(domainLogicMethod);196 assertEquals("void", domainLogicMethod.getReturnType().getName());197 //String returnValue = ReflectUtil.invokeMethod(domainLogicMethod.getName(), "hello world");198 }199 @Test200 public void domainLogicMustExtendSQLRecord() {201 ISQLTableType baseType = (ISQLTableType) TypeSystem.getByFullName("gosu.db.foo.BadExamples.Invalid");202 assertEquals("gosu.db.foo.BadExamples.Invalid", baseType.getName());203 assertEquals("gosu.db.foo.BadExamples", baseType.getNamespace());204 assertEquals("Invalid", baseType.getRelativeName());205 //assert the extension type exists ...206 IType extensionType = TypeSystem.getByFullName("gosu.db.foo.BadExampleExt.InvalidExt");207 assertEquals("gosu.db.foo.BadExampleExt.InvalidExt", extensionType.getName());208 assertEquals("gosu.db.foo.BadExampleExt", extensionType.getNamespace());209 assertEquals("InvalidExt", extensionType.getRelativeName());210 final String extensionTypeMethodName = "sayHi";211 IMethodInfo extensionTypeMethod = extensionType.getTypeInfo().getMethod(extensionTypeMethodName, JavaTypes.STRING());212 assertNotNull(extensionTypeMethod);213 // ... but that the base type is not decorated with the extension type's methods214 SQLTableTypeInfo ti = (SQLTableTypeInfo) baseType.getTypeInfo();215 assertEquals("Invalid", ti.getName());216 IMethodInfo domainLogicMethod = ti.getMethod(extensionTypeMethodName, JavaTypes.STRING());217 assertNull(domainLogicMethod);218 }219 @Test220 public void getSynthesizedProperty() {221 ISQLTableType result = (ISQLTableType) TypeSystem.getByFullNameIfValid("gosu.db.foo.Bars.Baz");222 assertNotNull(result);223 assertEquals("gosu.db.foo.Bars.Baz", result.getName());224 assertEquals("gosu.db.foo.Bars", result.getNamespace());225 assertEquals("Baz", result.getRelativeName());226 SQLTableTypeInfo ti = (SQLTableTypeInfo) result.getTypeInfo();227 assertEquals("Baz", ti.getName());228 IPropertyInfo domainLogicProperty = ti.getProperty("MeaningOfLife");229 assertNotNull(domainLogicProperty);230 assertTrue(domainLogicProperty.isReadable());231 assertFalse(domainLogicProperty.isWritable());232 assertEquals(JavaTypes.pINT(), domainLogicProperty.getFeatureType());233 //assertEquals(42, domainLogicProperty.getAccessor().getValue(result)); //TODO failing with seemingly legitimate error:234 /**235 * java.lang.IllegalArgumentException: object is not an instance of declaring class236 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)237 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)238 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)239 at gw.internal.gosu.parser.GosuPropertyInfo$GosuPropertyAccessor.getValue(GosuPropertyInfo.java:290)240 at gosu.db.plugin.SQLPluginTest.getInjectedProperty(SQLPluginTest.java:201)241 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...
Source:LombokTest.java
...107 public void trace() {108 log.trace("this is a message of level trace");109 }110 /**111 * 8.String getName()112 *113 * ãä½ç¨/æè¿°ã114 * è¿åloggerå®ä¾åï¼@Slf4jçæçloggerå®ä¾åçäºç±»çå
¨è·¯å¾ã115 *116 * ãåº/å
¥åè®°å½ã117 * [main] - log.getName(): com.zj.test.lombok.LombokTest118 *119 * ã使ç¨æ³¨æç¹ã120 *121 */122 @Test123 public void getName(){124 TestHelper.println("log.getName()",log.getName());125 }126 /** ----------------------------------------- lombok注解æµè¯ ---------------------------------------- */127 /**128 *129 * 1.@Setter/@Getter130 * çæsetter/getteræ¹æ³131 *132 * ç¨æ³133 * 1.ç¨å¨Typeä¸ï¼å为ææå±æ§çæsetter/getteræ¹æ³ã134 *135 * 2.ç¨å¨å±æ§ä¸ï¼å¯ä»¥ä¸ºç¹å®çå±æ§æ·»å setter/getteræ¹æ³ã136 *137 * 2.@ToStringï¼çætoString()æ¹æ³ï¼æ ¼å¼å¦ä¸ï¼138 * User(username=username, password=password)...
Source:ParentRunnerClassLoaderTest.java
...40 final Class<TestWithClassRule> originalTestClass = TestWithClassRule.class;41 final Class<?> waitClass = ParentRunnerClassLoaderTest.class;42 ParentRunner<FrameworkMethod> subParentRunner = new BlockJUnit4ClassRunner(originalTestClass) {43 @Override44 protected String getName() {45 return waitClass.getName();46 }47 };48 Description description = subParentRunner.getDescription();49 Class<?> result = description.getTestClass();50 assertEquals("Subclass of ParentRunner can override getName method and specify another test class for run, " +51 "we should maintain backwards compatibility with JUnit 4.12",52 waitClass, result53 );54 }55 private void runTestWithParentRunner(Class<?> testClass) throws InitializationError {56 ParentRunner<?> runner = new BlockJUnit4ClassRunner(testClass);57 runner.run(new RunNotifier());58 }59 private Class<?> wrapToClassLoader(Class<?> sourceClass) throws ClassNotFoundException {60 URL classpath = sourceClass.getProtectionDomain().getCodeSource().getLocation();61 VisibleClassLoader loader = new VisibleClassLoader(new URL[]{classpath}, this.getClass().getClassLoader());62 Class<?> testClassWithOwnClassLoader = loader.findClass(sourceClass.getName());63 assert testClassWithOwnClassLoader != sourceClass;64 return testClassWithOwnClassLoader;65 }66 private static class VisibleClassLoader extends URLClassLoader {67 public VisibleClassLoader(URL[] urls, ClassLoader parent) {68 super(urls, parent);69 }70 @Override // just making public71 public Class<?> findClass(String name) throws ClassNotFoundException {72 return super.findClass(name);73 }74 }75}...
Source:ParentStatementRunner.java
...27 * <p>This is a generally useful form of {@link ParentRunner} that can easily be customized.28 *29 * <p>This is used for JUnit3 based classes which may have multiple constructors (a default and30 * one that takes the test name) so it passes a {@link Dummy} class to the parent and overrides the31 * {@link #getName()} method. That works because this does not use any information from the supplied32 * class.33 */34public class ParentStatementRunner extends ParentRunner<DescribableStatement> {35 private final String name;36 private final List<DescribableStatement> statements;37 private final TestRule testRule;38 public ParentStatementRunner(Class<?> testClass, List<DescribableStatement> statements,39 RunnerParams runnerParams)40 throws InitializationError {41 super(Dummy.class);42 name = testClass.getName();43 this.statements = statements;44 testRule = runnerParams.getTestRule();45 }46 @Override47 protected String getName() {48 return name;49 }50 @Override51 protected List<DescribableStatement> getChildren() {52 return statements;53 }54 @Override55 protected Description describeChild(DescribableStatement child) {56 return child.getDescription();57 }58 @Override59 protected void runChild(final DescribableStatement child, RunNotifier notifier) {60 Description description = describeChild(child);61 Statement statement = child;...
Source:ParallelRunner.java
...38 try {39 fService.shutdown();40 fService.awaitTermination(TestinfoConf.ParallelRunTimeout, TimeUnit.MILLISECONDS);41 } catch (InterruptedException e) {42 System.out.printf("Runner Termination Error : %s, class=%s%n", runner.getDescription(), runner.getClass().getName());43 e.printStackTrace(System.out);44 }45 }46 });47 } else {48 System.out.printf("Unsupported Runner : %s, class=%s%n", runner.getDescription(), runner.getClass().getName());49 }50 return runner;51 }52 @Override53 public Runner getSuite(RunnerBuilder builder, java.lang.Class<?>[] classes)54 throws InitializationError {55 Runner suite = super.getSuite(builder, classes);56 return this.classes ? parallelize(suite) : suite;57 }58 @Override59 protected Runner getRunner(RunnerBuilder builder, Class<?> testClass)60 throws Throwable {61 Runner runner = super.getRunner(builder, testClass);62 return methods ? parallelize(runner) : runner;...
Source:IcuTestParentRunner.java
...21 * {@link org.junit.runners.model.TestClass} for the supplied {@code testClass} because that22 * requires that the {@code testClass} has only a single constructor and at least one ICU test23 * ({@code android.icu.dev.test.serializable.CoverageTest}) has more than one constructor.24 *25 * <p>This provides a dummy class and overrides the {@link #getName()} method to return the26 * correct name. The consequence of this is that it is not possible to use JUnit 4 annotations27 * related to the class, like {@link org.junit.BeforeClass}, {@link org.junit.ClassRule}, etc.28 */29abstract class IcuTestParentRunner<T> extends ParentRunner<T> {30 private final Class<?> testClass;31 IcuTestParentRunner(Class<?> testClass) throws InitializationError {32 super(DummyTestClass.class);33 this.testClass = testClass;34 }35 @Override36 protected String getName() {37 return testClass.getName();38 }39 /**40 * A dummy test class to pass to {@link ParentRunner} for it to validate and check for41 * annotations.42 *43 * <p>Must be public.44 */45 public static class DummyTestClass {46 }47}...
getName
Using AI Code Generation
1public class NameOfTest {2 public TestName name = new TestName();3 public void test() throws Exception {4 System.out.println(name.getMethodName());5 }6}7public class NameOfTest {8 public void test() throws Exception {9 System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());10 }11}12public class NameOfTest {13 public void test() throws Exception {14 System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());15 }16}17public class NameOfTest {18 public void test() throws Exception {19 System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());20 }21}22public class NameOfTest {23 public void test() throws Exception {24 System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());25 }26}27public class NameOfTest {28 public void test() throws Exception {29 System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());30 }31}32public class NameOfTest {33 public void test() throws Exception {34 System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());35 }36}37public class NameOfTest {38 public void test() throws Exception {
getName
Using AI Code Generation
1import java.lang.reflect.Method;2import java.util.Arrays;3import java.util.List;4import java.util.stream.Collectors;5import org.junit.runners.model.FrameworkMethod;6import com.google.common.base.Preconditions;7import com.google.common.base.Strings;8public class MethodNameUtils {9 private static final String TEST = "test";10 private static final String UNDERSCORE = "_";11 private static final String SPACE = " ";12 private static final String EMPTY = "";13 public static String getMethodName(FrameworkMethod frameworkMethod) {14 Method method = frameworkMethod.getMethod();15 String methodName = method.getName();16 Preconditions.checkArgument(methodName.startsWith(TEST), "Invalid method name: " + methodName);17 methodName = methodName.substring(TEST.length());18 methodName = methodName.replaceAll(UNDERSCORE, SPACE);19 methodName = methodName.trim();20 return methodName;21 }22 public static List<String> getMethodNames(List<FrameworkMethod> frameworkMethods) {23 return frameworkMethods.stream().map(frameworkMethod -> getMethodName(frameworkMethod)).collect(Collectors.toList());24 }25}
getName
Using AI Code Generation
1public static String getName(String methodName, Object[] args) {2 StringBuilder sb = new StringBuilder(methodName);3 sb.append("(");4 for (int i = 0; i < args.length; i++) {5 if (i > 0)6 sb.append(", ");7 sb.append(String.valueOf(args[i]));8 }9 sb.append(")");10 return sb.toString();11}12public static Runner getRunner(Class<? extends Runner> runnerClass, Object[] args) {13 try {14 Constructor<? extends Runner> constructor = runnerClass.getConstructor(Class.class, Object[].class);15 return constructor.newInstance(null, args);16 } catch (Exception e) {17 throw new RuntimeException(e);18 }19}20public static Runner getRunner(Class<? extends Runner> runnerClass, Object[] args) {21 try {22 Constructor<? extends Runner> constructor = runnerClass.getConstructor(Class.class, Object[].class);23 return constructor.newInstance(null, args);24 } catch (Exception e) {25 throw new RuntimeException(e);26 }27}28public static Runner getRunner(Class
LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.
Here are the detailed JUnit testing chapters to help you get started:
You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.
Get 100 minutes of automation test minutes FREE!!