Skip to content

Instantly share code, notes, and snippets.

@taichi
Created January 9, 2024 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taichi/ab5834f8565d7fd93a2e45988dffd67d to your computer and use it in GitHub Desktop.
Save taichi/ab5834f8565d7fd93a2e45988dffd67d to your computer and use it in GitHub Desktop.
Code template for JUnit5 used in Eclipse.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
<template autoinsert="true" context="java-members" deleted="false"
description="JUnit5 - Test Method" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.test" name="test"><![CDATA[@${testType:newType(org.junit.jupiter.api.Test)}
void ${testName}() throws Exception {
${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}${cursor}
}]]></template>
<template autoinsert="true" context="java-members" deleted="false"
description="JUnit5 - Test Method with a temporary directory." enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.testTemp" name="testtemp"><![CDATA[@${testType:newType(org.junit.jupiter.api.Test)}
void ${testName}(@${tempType:newType(org.junit.jupiter.api.io.TempDir)} ${pathType:newType(java.nio.file.Path)} tempDir) throws Exception {
${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}${cursor}
}]]></template>
<template autoinsert="true" context="java-statements" deleted="false"
description="JUnit5 - assertEquals" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.ase"
name="ase"><![CDATA[${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}assertEquals(${expected:var(java.lang.Object)}, ${actual:var(java.lang.Object)});
${cursor}]]></template>
<template autoinsert="true" context="java-statements" deleted="false"
description="JUnit5 - assertTrue" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.astrue"
name="astrue"><![CDATA[${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}assertTrue(${actual:var(java.lang.Object)});
${cursor}]]></template>
<template autoinsert="true" context="java-statements" deleted="false"
description="JUnit5 - assertFalse" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.asfalse"
name="asfalse"><![CDATA[${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}assertFalse(${actual:var(java.lang.Object)});
${cursor}]]></template>
<template autoinsert="true" context="java-statements" deleted="false"
description="JUnit5 - assertNotNull" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.asnonnull"
name="asnonnull"><![CDATA[${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}assertNotNull(${actual:var(java.lang.Object)});
${cursor}]]></template>
<template autoinsert="true" context="java-statements" deleted="false"
description="JUnit5 - assertNull" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.asnull"
name="asnull"><![CDATA[${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}assertNull(${actual:var(java.lang.Object)});
${cursor}]]></template>
<template autoinsert="true" context="java-statements" deleted="false"
description="JUnit5 - fail" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.fail"
name="asnonnull"><![CDATA[${staticImport:importStatic('org.junit.jupiter.api.Assertions.*')}}fail();
${cursor}]]></template>
<template autoinsert="false" context="java-members" deleted="false"
description="JUnit5 - Setup Method (same as init)" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.setup" name="setup"><![CDATA[@${initType:newType(org.junit.jupiter.api.BeforeEach)}
void init(${infoType:newType(org.junit.jupiter.api.TestInfo)} info) throws Exception {
${cursor}
}]]></template>
<template autoinsert="false" context="java-members" deleted="false"
description="JUnit5 - Init Method" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.init" name="init"><![CDATA[@${initType:newType(org.junit.jupiter.api.BeforeEach)}
void init(${infoType:newType(org.junit.jupiter.api.TestInfo)} info) throws Exception {
${cursor}
}]]></template>
<template autoinsert="false" context="java-members" deleted="false"
description="JUnit5 - Teardown Method" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.teardown" name="teardwon"><![CDATA[@${setupType:newType(org.junit.jupiter.api.AfterEach)}
void tearDown(${infoType:newType(org.junit.jupiter.api.TestInfo)} info) throws Exception {
${cursor}
}]]></template>
<template autoinsert="false" context="java-members" deleted="false"
description="JUnit5 - Setup All Method(same as initAll)" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.setupall" name="setupall"><![CDATA[@${initType:newType(org.junit.jupiter.api.BeforeAll)}
static void initAll(${infoType:newType(org.junit.jupiter.api.TestInfo)} info) throws Exception {
${cursor}
}]]></template>
<template autoinsert="false" context="java-members" deleted="false"
description="JUnit5 - Init All Method" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.initall" name="initall"><![CDATA[@${initType:newType(org.junit.jupiter.api.BeforeAll)}
static void initAll(${infoType:newType(org.junit.jupiter.api.TestInfo)} info) throws Exception {
${cursor}
}]]></template>
<template autoinsert="false" context="java-members" deleted="false"
description="JUnit5 - Teardown All Method" enabled="true"
id="org.eclipse.jdt.ui.templates.junit5.teardownall" name="teardwonall"><![CDATA[@${setupType:newType(org.junit.jupiter.api.AfterAll)}
static void tearDownAll(${infoType:newType(org.junit.jupiter.api.TestInfo)} info) throws Exception {
${cursor}
}]]></template></templates>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment