From 3bb8125880cc24d200aa2fcbfad277e646c29077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lios=20GILLES?= Date: Fri, 3 Jul 2026 00:29:41 +0200 Subject: [PATCH] test: add SWTBot Missing Tests and Missing Test Methods view tests - Add MissingViewsSWTBotTest: opens the Show View dialog, expands MoreUnit category, selects view, asserts it opens - Test Resource: MyClassWithMethods.txt / MyClassWithMethodsTest.txt (JUnit 5 partial test coverage scenario) --- .../views/MissingViewsSWTBotTest.java | 135 ++++++++++++++++++ .../org/moreunit/views/MyClassWithMethods.txt | 14 ++ .../moreunit/views/MyClassWithMethodsTest.txt | 13 ++ 3 files changed, 162 insertions(+) create mode 100644 org.moreunit.swtbot.test/test/org/moreunit/views/MissingViewsSWTBotTest.java create mode 100644 org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethods.txt create mode 100644 org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethodsTest.txt diff --git a/org.moreunit.swtbot.test/test/org/moreunit/views/MissingViewsSWTBotTest.java b/org.moreunit.swtbot.test/test/org/moreunit/views/MissingViewsSWTBotTest.java new file mode 100644 index 00000000..5300e105 --- /dev/null +++ b/org.moreunit.swtbot.test/test/org/moreunit/views/MissingViewsSWTBotTest.java @@ -0,0 +1,135 @@ +package org.moreunit.views; + +import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive; + +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.junit5.SWTBotJunit5Extension; +import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.moreunit.JavaProjectSWTBotTestHelper; +import org.moreunit.test.context.Project; +import org.moreunit.test.context.Properties; +import org.moreunit.test.context.TestType; + +@ExtendWith(SWTBotJunit5Extension.class) +public class MissingViewsSWTBotTest extends JavaProjectSWTBotTestHelper +{ + @BeforeEach + public void closeEditors() + { + for (var editor : bot.editors()) + editor.close(); + } + + @Test + @Project( + mainCls = "org:SomeUntestedClass", + properties = @Properties( + testType = TestType.JUNIT5, + testClassNameTemplate = "${srcFile}Test")) + public void should_open_missing_tests_per_project_view() + { + selectAndReturnJavaProjectFromPackageExplorer(); + + bot.menu("Window").menu("Show View").menu("Other...").click(); + bot.waitUntil(shellIsActive("Show View")); + + bot.text(0).setText("Missing Tests per Project"); + bot.waitUntil(new DefaultCondition() + { + @Override + public boolean test() + { + return bot.tree().rowCount() > 0; + } + @Override + public String getFailureMessage() + { + return "Missing Tests per Project view not found in Show View dialog"; + } + }, 10000); + + bot.tree().expandNode("MoreUnit").select("Missing Tests per Project"); + bot.button("Open").click(); + + bot.waitUntil(new DefaultCondition() + { + @Override + public boolean test() + { + try + { + ((org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)bot).viewByTitle("Missing Tests per Project"); + return true; + } + catch (WidgetNotFoundException e) + { + return false; + } + } + @Override + public String getFailureMessage() + { + return "Missing Tests per Project view did not open"; + } + }, 10000); + } + + @Test + @Project( + mainSrc = "MyClassWithMethods.txt", + testSrc = "MyClassWithMethodsTest.txt", + properties = @Properties( + testType = TestType.JUNIT5, + testClassNameTemplate = "${srcFile}Test")) + public void should_open_missing_test_methods_view() + { + selectAndReturnJavaProjectFromPackageExplorer(); + + bot.menu("Window").menu("Show View").menu("Other...").click(); + bot.waitUntil(shellIsActive("Show View")); + + bot.text(0).setText("Missing Test Methods"); + bot.waitUntil(new DefaultCondition() + { + @Override + public boolean test() + { + return bot.tree().rowCount() > 0; + } + @Override + public String getFailureMessage() + { + return "Missing Test Methods view not found in Show View dialog"; + } + }, 10000); + + bot.tree().expandNode("MoreUnit").select("Missing Test Methods"); + bot.button("Open").click(); + + bot.waitUntil(new DefaultCondition() + { + @Override + public boolean test() + { + try + { + ((org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)bot).viewByTitle("Missing Test Methods"); + return true; + } + catch (WidgetNotFoundException e) + { + return false; + } + } + @Override + public String getFailureMessage() + { + return "Missing Test Methods view did not open"; + } + }, 10000); + } +} diff --git a/org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethods.txt b/org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethods.txt new file mode 100644 index 00000000..8f944830 --- /dev/null +++ b/org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethods.txt @@ -0,0 +1,14 @@ +package testing; + +public class MyClassWithMethods +{ + public int methodOne() + { + return 1; + } + + public String methodTwo() + { + return "two"; + } +} diff --git a/org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethodsTest.txt b/org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethodsTest.txt new file mode 100644 index 00000000..44d04092 --- /dev/null +++ b/org.moreunit.swtbot.test/test/org/moreunit/views/MyClassWithMethodsTest.txt @@ -0,0 +1,13 @@ +package testing; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class MyClassWithMethodsTest +{ + @Test + public void testMethodOne() + { + assertEquals(1, new MyClassWithMethods().methodOne()); + } +}