Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public class XtendValidator extends XbaseWithAnnotationsValidator {
"org.junit.BeforeClass",
"org.junit.AfterClass",

// JUnit5 annotations
// JUnit6 annotations
"org.junit.jupiter.api.Test",
"org.junit.jupiter.api.BeforeEach",
"org.junit.jupiter.api.AfterEach",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package org.eclipse.xtend.ide.tests.quickfix

import org.eclipse.xtend.ide.buildpath.Junit4LibClasspathAdder
import org.eclipse.xtend.ide.buildpath.Junit5LibClasspathAdder
import org.eclipse.xtend.ide.buildpath.Junit6LibClasspathAdder
import org.eclipse.xtend.ide.tests.XtendIDEInjectorProvider
import org.eclipse.xtend.ide.tests.buildpath.AbstractJunitLibClasspathAdderTestCase
import org.eclipse.xtext.diagnostics.Diagnostic
Expand Down Expand Up @@ -80,7 +80,7 @@ class AddJunitLibToClasspathQuickfixTest extends AbstractJunitLibClasspathAdderT
}

@Test
def void addJUnit5LibToPluginProjectClasspath() {
def void addJUnit6LibToPluginProjectClasspath() {
val content = '''
import org.junit.jupiter.api|.Test

Expand All @@ -91,14 +91,14 @@ class AddJunitLibToClasspathQuickfixTest extends AbstractJunitLibClasspathAdderT
'''
create('FooTest2.xtend', content)
.assertIssueCodes(Diagnostic.LINKING_DIAGNOSTIC)
.assertResolutionLabels('Add JUnit 5 lib to classpath')
.assertResolutionLabels('Add JUnit 6 lib to classpath')
.assertModelAfterQuickfix(content.replace('|', ''))
assertImportPackages(#["org.junit.jupiter.api;version=\"[5.1.0,6.0.0)\""]) // just test 1
assertImportPackages(#["org.junit.jupiter.api;version=\"[6.0.0,7.0.0)\""]) // just test 1
}


@Test
def void addJUnit5LibToProjectClasspath() {
def void addJUnit6LibToProjectClasspath() {
removePluginNature
val content = '''
import org.junit.jupiter.api|.Test
Expand All @@ -110,11 +110,11 @@ class AddJunitLibToClasspathQuickfixTest extends AbstractJunitLibClasspathAdderT
'''
create('FooTest.xtend', content)
.assertIssueCodes(Diagnostic.LINKING_DIAGNOSTIC)
.assertResolutionLabels('Add JUnit 5 lib to classpath')
.assertResolutionLabels('Add JUnit 6 lib to classpath')
.assertModelAfterQuickfix(content.replace('|', ''))
assertClasspath(
'classpath should contain a JUnit 5 container entry',
Junit5LibClasspathAdder.JUNIT5_LIBRARY_PATH
'classpath should contain a JUnit 6 container entry',
Junit6LibClasspathAdder.JUNIT6_LIBRARY_PATH
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package org.eclipse.xtend.ide.tests.buildpath
import org.eclipse.core.runtime.NullProgressMonitor
import org.eclipse.jdt.core.JavaCore
import org.eclipse.xtend.ide.buildpath.Junit4LibClasspathAdder
import org.eclipse.xtend.ide.buildpath.Junit5LibClasspathAdder
import org.eclipse.xtend.ide.buildpath.Junit6LibClasspathAdder
import org.eclipse.xtend.ide.tests.XtendIDEInjectorProvider
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
Expand All @@ -28,7 +28,7 @@ class JunitLibClasspathAdderTest extends AbstractJunitLibClasspathAdderTestCase

@Inject Junit4LibClasspathAdder junit4LibAdder

@Inject Junit5LibClasspathAdder junit5LibAdder
@Inject Junit6LibClasspathAdder junit6LibAdder

@Test
def void addJUnit4LibToPluginProjectClasspath() {
Expand All @@ -48,18 +48,18 @@ class JunitLibClasspathAdderTest extends AbstractJunitLibClasspathAdderTestCase
}

@Test
def void addJUnit5LibToPluginProjectClasspath() {
junit5LibAdder.addLibsToClasspath(JavaCore.create(project), new NullProgressMonitor)
assertRequireBundles(Junit5LibClasspathAdder.BUNDLE_IDS)
def void addJUnit6LibToPluginProjectClasspath() {
junit6LibAdder.addLibsToClasspath(JavaCore.create(project), new NullProgressMonitor)
assertRequireBundles(Junit6LibClasspathAdder.BUNDLE_IDS)
}

@Test
def void addJUnit5LibToProjectClasspath() {
def void addJUnit6LibToProjectClasspath() {
removePluginNature
junit5LibAdder.addLibsToClasspath(JavaCore.create(project), new NullProgressMonitor)
junit6LibAdder.addLibsToClasspath(JavaCore.create(project), new NullProgressMonitor)
assertClasspath(
'classpath should contain a JUnit 5 container entry',
Junit5LibClasspathAdder.JUNIT5_LIBRARY_PATH
'classpath should contain a JUnit 6 container entry',
Junit6LibClasspathAdder.JUNIT6_LIBRARY_PATH
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.xtend.ide.buildpath.Junit4LibClasspathAdder;
import org.eclipse.xtend.ide.buildpath.Junit5LibClasspathAdder;
import org.eclipse.xtend.ide.buildpath.Junit6LibClasspathAdder;
import org.eclipse.xtend.ide.tests.XtendIDEInjectorProvider;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
Expand All @@ -38,7 +38,7 @@ public class JunitLibClasspathAdderTest extends AbstractJunitLibClasspathAdderTe
private Junit4LibClasspathAdder junit4LibAdder;

@Inject
private Junit5LibClasspathAdder junit5LibAdder;
private Junit6LibClasspathAdder junit6LibAdder;

@Test
public void addJUnit4LibToPluginProjectClasspath() {
Expand Down Expand Up @@ -68,21 +68,21 @@ public void addJUnit4LibToProjectClasspath() {
}

@Test
public void addJUnit5LibToPluginProjectClasspath() {
public void addJUnit6LibToPluginProjectClasspath() {
IJavaProject _create = JavaCore.create(this.workbenchHelper.getProject());
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
this.junit5LibAdder.addLibsToClasspath(_create, _nullProgressMonitor);
this.assertRequireBundles(Junit5LibClasspathAdder.BUNDLE_IDS);
this.junit6LibAdder.addLibsToClasspath(_create, _nullProgressMonitor);
this.assertRequireBundles(Junit6LibClasspathAdder.BUNDLE_IDS);
}

@Test
public void addJUnit5LibToProjectClasspath() {
public void addJUnit6LibToProjectClasspath() {
this.removePluginNature();
IJavaProject _create = JavaCore.create(this.workbenchHelper.getProject());
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
this.junit5LibAdder.addLibsToClasspath(_create, _nullProgressMonitor);
this.junit6LibAdder.addLibsToClasspath(_create, _nullProgressMonitor);
this.assertClasspath(
"classpath should contain a JUnit 5 container entry",
Junit5LibClasspathAdder.JUNIT5_LIBRARY_PATH);
"classpath should contain a JUnit 6 container entry",
Junit6LibClasspathAdder.JUNIT6_LIBRARY_PATH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.google.inject.Inject;
import org.eclipse.xtend.ide.buildpath.Junit4LibClasspathAdder;
import org.eclipse.xtend.ide.buildpath.Junit5LibClasspathAdder;
import org.eclipse.xtend.ide.buildpath.Junit6LibClasspathAdder;
import org.eclipse.xtend.ide.tests.XtendIDEInjectorProvider;
import org.eclipse.xtend.ide.tests.buildpath.AbstractJunitLibClasspathAdderTestCase;
import org.eclipse.xtend2.lib.StringConcatenation;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void addJUnit4LibToProjectClasspath() {
}

@Test
public void addJUnit5LibToPluginProjectClasspath() {
public void addJUnit6LibToPluginProjectClasspath() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.junit.jupiter.api|.Test");
_builder.newLine();
Expand All @@ -108,12 +108,12 @@ public void addJUnit5LibToPluginProjectClasspath() {
_builder.append("}");
_builder.newLine();
final String content = _builder.toString();
this.builder.create("FooTest2.xtend", content).assertIssueCodes(Diagnostic.LINKING_DIAGNOSTIC).assertResolutionLabels("Add JUnit 5 lib to classpath").assertModelAfterQuickfix(content.replace("|", ""));
this.assertImportPackages(new String[] { "org.junit.jupiter.api;version=\"[5.1.0,6.0.0)\"" });
this.builder.create("FooTest2.xtend", content).assertIssueCodes(Diagnostic.LINKING_DIAGNOSTIC).assertResolutionLabels("Add JUnit 6 lib to classpath").assertModelAfterQuickfix(content.replace("|", ""));
this.assertImportPackages(new String[] { "org.junit.jupiter.api;version=\"[6.0.0,7.0.0)\"" });
}

@Test
public void addJUnit5LibToProjectClasspath() {
public void addJUnit6LibToProjectClasspath() {
this.removePluginNature();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.junit.jupiter.api|.Test");
Expand All @@ -130,9 +130,9 @@ public void addJUnit5LibToProjectClasspath() {
_builder.append("}");
_builder.newLine();
final String content = _builder.toString();
this.builder.create("FooTest.xtend", content).assertIssueCodes(Diagnostic.LINKING_DIAGNOSTIC).assertResolutionLabels("Add JUnit 5 lib to classpath").assertModelAfterQuickfix(content.replace("|", ""));
this.builder.create("FooTest.xtend", content).assertIssueCodes(Diagnostic.LINKING_DIAGNOSTIC).assertResolutionLabels("Add JUnit 6 lib to classpath").assertModelAfterQuickfix(content.replace("|", ""));
this.assertClasspath(
"classpath should contain a JUnit 5 container entry",
Junit5LibClasspathAdder.JUNIT5_LIBRARY_PATH);
"classpath should contain a JUnit 6 container entry",
Junit6LibClasspathAdder.JUNIT6_LIBRARY_PATH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
/**
* @author vivienjovet - Initial contribution and API
*/
public class Junit5LibClasspathAdder extends AbstractLibClasspathAdder {
public class Junit6LibClasspathAdder extends AbstractLibClasspathAdder {

public static final IPath JUNIT5_LIBRARY_PATH = new Path("org.eclipse.jdt.junit.JUNIT_CONTAINER/5");
public static final IPath JUNIT6_LIBRARY_PATH = new Path("org.eclipse.jdt.junit.JUNIT_CONTAINER/6");
public static final String[] BUNDLE_IDS = new String[] {
"org.junit",
"org.hamcrest.core",
Expand All @@ -27,7 +27,7 @@ public class Junit5LibClasspathAdder extends AbstractLibClasspathAdder {

@Override
protected IClasspathEntry createContainerClasspathEntry() {
return JavaCore.newContainerEntry(JUNIT5_LIBRARY_PATH);
return JavaCore.newContainerEntry(JUNIT6_LIBRARY_PATH);
}

@Override
Expand All @@ -38,13 +38,13 @@ protected String[] getBundleIds() {
@Override
protected String[] getImportedPackages() {
return new String[] {
"org.junit.jupiter.api;version=\"[5.1.0,6.0.0)\"",
"org.junit.jupiter.api.condition;version=\"[5.1.0,6.0.0)\"",
"org.junit.jupiter.api.extension;version=\"[5.1.0,6.0.0)\"",
"org.junit.jupiter.api.function;version=\"[5.1.0,6.0.0)\"",
"org.junit.jupiter.api.io;version=\"[5.1.0,6.0.0)\"",
"org.junit.jupiter.api.parallel;version=\"[5.1.0,6.0.0)\"",
"org.junit.platform.commons.support;version=\"[1.0.0,2.0.0)\";resolution:=optional"
"org.junit.jupiter.api;version=\"[6.0.0,7.0.0)\"",
"org.junit.jupiter.api.condition;version=\"[6.0.0,7.0.0)\"",
"org.junit.jupiter.api.extension;version=\"[6.0.0,7.0.0)\"",
"org.junit.jupiter.api.function;version=\"[6.0.0,7.0.0)\"",
"org.junit.jupiter.api.io;version=\"[6.0.0,7.0.0)\"",
"org.junit.jupiter.api.parallel;version=\"[6.0.0,7.0.0)\"",
"org.junit.platform.commons.support;version=\"[6.0.0,7.0.0)\";resolution:=optional"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import org.eclipse.xtend.core.xtend.XtendPackage;
import org.eclipse.xtend.core.xtend.XtendTypeDeclaration;
import org.eclipse.xtend.ide.buildpath.Junit4LibClasspathAdder;
import org.eclipse.xtend.ide.buildpath.Junit5LibClasspathAdder;
import org.eclipse.xtend.ide.buildpath.Junit6LibClasspathAdder;
import org.eclipse.xtend.ide.buildpath.XtendLibClasspathAdder;
import org.eclipse.xtend.ide.codebuilder.InsertionOffsets;
import org.eclipse.xtend.ide.codebuilder.MemberFromSuperImplementor;
Expand Down Expand Up @@ -139,7 +139,7 @@ public class XtendQuickfixProvider extends XbaseQuickfixProvider {

@Inject private Junit4LibClasspathAdder junit4LibAdder;

@Inject private Junit5LibClasspathAdder junit5LibAdder;
@Inject private Junit6LibClasspathAdder junit6LibAdder;

@Inject private IJavaProjectProvider projectProvider;

Expand Down Expand Up @@ -217,13 +217,13 @@ public void fixJunitNotOnClasspath(final Issue issue, final IssueResolutionAccep
String type = issue.getData()[0];

if (type.startsWith("org.junit.jupiter.")) {
acceptor.accept(issue, "Add JUnit 5 lib to classpath", "Add JUnit 5 lib to classpath", "julaunch.gif",
acceptor.accept(issue, "Add JUnit 6 lib to classpath", "Add JUnit 6 lib to classpath", "julaunch.gif",
new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
ResourceSet resourceSet = element.eResource().getResourceSet();
IJavaProject javaProject = projectProvider.getJavaProject(resourceSet);
junit5LibAdder.addLibsToClasspath(javaProject, new NullProgressMonitor());
junit6LibAdder.addLibsToClasspath(javaProject, new NullProgressMonitor());
}
});
} else if (type.startsWith("org.junit.")) {
Expand Down
9 changes: 2 additions & 7 deletions org.eclipse.xtext.dev-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
<url>git@github.com:eclipse-xtext/xtext.git</url>
</scm>
<properties>
<junit-platform-version>1.14.0</junit-platform-version>
<junit-jupiter-version>5.14.0</junit-jupiter-version>
<junit-platform-version>6.0.1</junit-platform-version>
<junit-jupiter-version>6.0.1</junit-jupiter-version>
<org.eclipse.emf.mwe2-version>2.25.0</org.eclipse.emf.mwe2-version>
<org.eclipse.emf.mwe-version>1.19.0</org.eclipse.emf.mwe-version>
<org.eclipse.lsp4j-version>1.0.0</org.eclipse.lsp4j-version>
Expand Down Expand Up @@ -440,11 +440,6 @@
<artifactId>junit-platform-launcher</artifactId>
<version>${junit-platform-version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform-version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ <h2 id="tutorial-unit-tests">Unit Testing the Language</h2>
}
</code></pre>

<p><em>Note</em>: When using JUnit 5 the <a href="https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/extensions/InjectionExtension.java">InjectionExtension</a> is used instead of the XtextRunner. The Xtext code generator generates the example slightly different, depending on which option you have chosen in the <em>New Xtext Project</em> wizard.</p>
<p><em>Note</em>: When using JUnit 6 the <a href="https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/extensions/InjectionExtension.java">InjectionExtension</a> is used instead of the XtextRunner. The Xtext code generator generates the example slightly different, depending on which option you have chosen in the <em>New Xtext Project</em> wizard.</p>
</li>
<li>
<p>The utility class <a href="https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/util/ParseHelper.java">ParseHelper</a> allows to parse an arbitrary string into a <em>Domainmodel</em>. The model itself can be traversed and checked afterwards. A static import of <a href="https://junit.org/junit4/javadoc/4.13/org/junit/Assert.html">Assert</a> leads to concise and readable test cases. You can rewrite the generated test case as follows:</p>
Expand Down
6 changes: 3 additions & 3 deletions org.eclipse.xtext.doc/contents/303_runtime_concepts.html
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ <h3 id="encoding-of-an-xtextresource">Encoding of an XtextResource</h3>

<h2 id="testing">Unit Testing</h2>

<p>Automated tests are crucial for the maintainability and the quality of a software product. That is why it is strongly recommended to write unit tests for your language, too. The Xtext project wizard creates test projects for that purpose, which simplify the setup procedure for the basic language implementation as well as platform-specific integrations. It supports an option to either create your tests for JUnit 4 or JUnit 5. Depending on your choice your test layout will vary in some details.</p>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be fixed in (https://github.com/eclipse-xtext/xtext-website) pr against main

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<p>Automated tests are crucial for the maintainability and the quality of a software product. That is why it is strongly recommended to write unit tests for your language, too. The Xtext project wizard creates test projects for that purpose, which simplify the setup procedure for the basic language implementation as well as platform-specific integrations. It supports an option to either create your tests for JUnit 4 or JUnit 6. Depending on your choice your test layout will vary in some details.</p>

<h3 id="creating-a-simple-test-class">Creating a Simple Test Class</h3>

Expand All @@ -830,7 +830,7 @@ <h3 id="creating-a-simple-test-class">Creating a Simple Test Class</h3>

<p>This configuration will make sure that you can use dependency injection in your test class, and that the global EMF registries are properly populated before and cleaned up after each test.</p>

<p>A test class for JUnit 5 looks quite similar. Instead of runners JUnit 5 has a notion of <a href="https://junit.org/junit5/docs/current/user-guide/#extensions">Extensions</a>. While there can only be one runner per test class for JUnit 4 there could be multiple extensions for JUnit 5. The replacement for the XtextRunner is the new <a href="https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/extensions/InjectionExtension.java">InjectionExtension</a>. Still needed is the language specific <a href="https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/IInjectorProvider.java">IInjectorProvider</a>. Instead of <code>org.junit.Test</code> you have to annotate your cases with <a href="https://github.com/junit-team/junit5/blob/master/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Test.java">org.junit.jupiter.api.Test</a> and import the methods from <a href="https://github.com/junit-team/junit5/blob/master/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assertions.java">org.junit.jupiter.api.Assertions</a>. A simple test class for JUnit 5 will then look like this:</p>
<p>A test class for JUnit 6 looks quite similar. Instead of runners JUnit 6 has a notion of <a href="https://junit.org/junit5/docs/current/user-guide/#extensions">Extensions</a>. While there can only be one runner per test class for JUnit 4 there could be multiple extensions for JUnit 6. The replacement for the XtextRunner is the new <a href="https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/extensions/InjectionExtension.java">InjectionExtension</a>. Still needed is the language specific <a href="https://github.com/eclipse-xtext/xtext/blob/main/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/IInjectorProvider.java">IInjectorProvider</a>. Instead of <code>org.junit.Test</code> you have to annotate your cases with <a href="https://github.com/junit-team/junit5/blob/master/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Test.java">org.junit.jupiter.api.Test</a> and import the methods from <a href="https://github.com/junit-team/junit5/blob/master/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assertions.java">org.junit.jupiter.api.Assertions</a>. A simple test class for JUnit 6 will then look like this:</p>

<pre><code class="language-xtend">import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
Expand Down Expand Up @@ -903,7 +903,7 @@ <h3 id="testing-multiple-languages">Testing Multiple Languages</h3>
}

// @RunWith(XtextRunner.class) // JUnit 4
@ExtendWith(InjectionExtension.class) // JUnit 5
@ExtendWith(InjectionExtension.class) // JUnit 6
@InjectWith(MyLanguageWithDependenciesInjectorProvider.class)
public class YourTest {
...
Expand Down
Loading
Loading