Re: [scala-ide-dev] Cannot run single scalatest test over JUnit

58 views
Skip to first unread message

Simon Schäfer

unread,
Jan 15, 2016, 11:42:28 AM1/15/16
to scala-...@googlegroups.com
I wouldn't run ScalaTest tests with JUnit. Use the ScalaTest integration in Scala IDE instead. You said that it works sometimes but I wonder why it works at all because it is not supposed to find any tests. It shouldn't break that is sure, but given that the error originates in the Java tooling, there is not much we can do beside from not showing up the "run as JUnit test" at all.

On 12/23/2015 01:28 PM, Sergey Alaev wrote:
MyTest.scala:

@RunWith(classOf[JUnitRunner])
class MyTest extends FunSuite {
  test("my test") { .... }
.....
}

When I try to run this single scala file (Run As -> Scala JUnit Test), I get InvocationTargetException.

Details:
Eclipse Mars 4.5.1
Scala IDE for Eclipse 4.3.0.v-2_11-201512011536-499c89a

Sometimes it works, but on large Scala projects it is always reproducible. But running package or project works well.

Stacktrace:

!ENTRY org.eclipse.jdt.junit 4 4 2015-12-23 15:18:15.810
!MESSAGE Error
!STACK 0
java.lang.reflect.InvocationTargetException
        at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:420)
        at org.eclipse.ui.internal.WorkbenchWindow$14.run(WorkbenchWindow.java:2156)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
        at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2152)
        at org.eclipse.jdt.internal.junit.util.TestSearchEngine.findTests(TestSearchEngine.java:47)
        at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.findTypesToLaunch(JUnitLaunchShortcut.java:218)
        at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.findTypeToLaunch(JUnitLaunchShortcut.java:207)
        at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.launch(JUnitLaunchShortcut.java:183)
        at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.launch(JUnitLaunchShortcut.java:114)
        at org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension.launch(LaunchShortcutExtension.java:420)
        at org.eclipse.debug.internal.ui.contextlaunching.ContextRunner.launchShortcut(ContextRunner.java:204)
        at org.eclipse.debug.internal.ui.contextlaunching.ContextRunner.showShortcutSelectionDialog(ContextRunner.java:276)
        at org.eclipse.debug.internal.ui.contextlaunching.ContextRunner.selectAndLaunch(ContextRunner.java:140)
        at org.eclipse.debug.internal.ui.contextlaunching.ContextRunner.launch(ContextRunner.java:81)
        at org.eclipse.debug.ui.actions.AbstractLaunchToolbarAction.run(AbstractLaunchToolbarAction.java:82)
        at org.eclipse.debug.ui.actions.AbstractLaunchHistoryAction.runWithEvent(AbstractLaunchHistoryAction.java:420)
        at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:237)
        at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:228)
        at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
        at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
        at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:462)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1329)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
        at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.NullPointerException
        at org.eclipse.jdt.internal.compiler.lookup.ClassScope.buildMethods(ClassScope.java:330)
        at org.eclipse.jdt.internal.compiler.lookup.ClassScope.buildFieldsAndMethods(ClassScope.java:183)
        at org.eclipse.jdt.internal.compiler.lookup.ClassScope.buildFieldsAndMethods(ClassScope.java:194)
        at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildFieldsAndMethods(CompilationUnitScope.java:84)
        at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:303)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.accept(HierarchyResolver.java:166)
        at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:186)
        at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:201)
        at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2868)
        at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.getTypeBinding(QualifiedTypeReference.java:97)
        at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:495)
        at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:594)
        at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:590)
        at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveSuperType(TypeReference.java:564)
        at org.eclipse.jdt.internal.compiler.lookup.ClassScope.findSupertype(ClassScope.java:1318)
        at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectSuperInterfaces(ClassScope.java:1050)
        at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectTypeHierarchy(ClassScope.java:1112)
        at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.connectTypeHierarchy(CompilationUnitScope.java:321)
        at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:325)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:816)
        at org.eclipse.jdt.internal.core.hierarchy.RegionBasedHierarchyBuilder.createTypeHierarchyBasedOnRegion(RegionBasedHierarchyBuilder.java:91)
        at org.eclipse.jdt.internal.core.hierarchy.RegionBasedHierarchyBuilder.build(RegionBasedHierarchyBuilder.java:60)
        at org.eclipse.jdt.internal.core.hierarchy.RegionBasedTypeHierarchy.compute(RegionBasedTypeHierarchy.java:98)
        at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.refresh(TypeHierarchy.java:1268)
        at org.eclipse.jdt.internal.core.CreateTypeHierarchyOperation.executeOperation(CreateTypeHierarchyOperation.java:90)
        at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:729)
        at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:789)
        at org.eclipse.jdt.core.JavaCore.newTypeHierarchy(JavaCore.java:4560)
        at org.eclipse.jdt.internal.junit.launcher.JUnit4TestFinder.findTestsInContainer(JUnit4TestFinder.java:128)
        at org.eclipse.jdt.internal.junit.util.TestSearchEngine$1.run(TestSearchEngine.java:41)
        at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)


--
You received this message because you are subscribed to the Google Groups "Scala IDE Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-dev/fe4549b0-e5a4-4c0f-ad50-75a409f5466c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Schäfer

unread,
Jan 15, 2016, 11:47:20 AM1/15/16
to scala-...@googlegroups.com


On 01/15/2016 05:42 PM, Simon Schäfer wrote:
I wouldn't run ScalaTest tests with JUnit. Use the ScalaTest integration in Scala IDE instead. You said that it works sometimes but I wonder why it works at all because it is not supposed to find any tests. It shouldn't break that is sure, but given that the error originates in the Java tooling, there is not much we can do beside from not showing up the "run as JUnit test" at all.
Actually there is not a lot we can do here. You told it with "@RunWith(classOf[JUnitRunner])" that it can be run as a JUnit test, which is the reason why it shows the menu entry. Later, the Java tooling breaks, which is not our fault and time consuming for us to fix. Just don't run it as a JUnit test and you should be fine.

iulian dragos

unread,
Jan 16, 2016, 11:58:00 AM1/16/16
to scala-ide-dev
In fact, there is support for JUnit tests, but it relies on the Scala JUnit finder: http://scala-ide.org/docs/current-user-doc/features/test-finder/index.html It should work, but I agree with Simon that using the ScalaTest plugin is the preferred way.


For more options, visit https://groups.google.com/d/optout.



--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais
Reply all
Reply to author
Forward
0 new messages