public void testCreateConfiguration() throws IOException, ExecutionException { Module module1 = getModule1(); PsiClass psiClass = findTestA(module1); JUnitConfiguration configuration = createConfiguration(psiClass); assertEquals( Collections.singleton(module1), ContainerUtilRt.newHashSet(configuration.getModules())); checkClassName(psiClass.getQualifiedName(), configuration); assertEquals(psiClass.getName(), configuration.getName()); checkTestObject(JUnitConfiguration.TEST_CLASS, configuration); Module module2 = getModule2(); Assertion.compareUnordered(new Module[] {module1, module2}, configuration.getValidModules()); PsiClass innerTest = findClass(module1, INNER_TEST_NAME); configuration = createJUnitConfiguration( innerTest, TestClassConfigurationProducer.class, new MapDataContext()); checkClassName(RT_INNER_TEST_NAME, configuration); checkCanRun(configuration); PsiMethod[] testMethod = innerTest.findMethodsByName("test", false); assertEquals(1, testMethod.length); configuration = createConfiguration(testMethod[0]); checkClassName(RT_INNER_TEST_NAME, configuration); checkMethodName("test", configuration); checkTestObject(JUnitConfiguration.TEST_METHOD, configuration); checkCanRun(configuration); PsiMethod mainMethod = innerTest.findMethodsByName("main", false)[0]; ApplicationConfiguration appConfiguration = createConfiguration(mainMethod); assertEquals(RT_INNER_TEST_NAME, appConfiguration.MAIN_CLASS_NAME); checkCanRun(configuration); }
public void testModulesSelector() throws ConfigurationException { if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return; Module module1 = getModule1(); Module module2 = getModule2(); JUnitConfigurable editor = new JUnitConfigurable(myProject); try { JUnitConfiguration configuration = createConfiguration(findTestA(module2)); editor.getComponent(); // To get all the watchers installed. Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration); JComboBox comboBox = editor.getModulesComponent(); configurable.reset(); assertFalse(configurable.isModified()); assertEquals(module2.getName(), ((Module) comboBox.getSelectedItem()).getName()); assertEquals( ModuleManager.getInstance(myProject).getModules().length + 1, comboBox.getModel().getSize()); // no module comboBox.setSelectedItem(module1); assertTrue(configurable.isModified()); configurable.apply(); assertFalse(configurable.isModified()); assertEquals( Collections.singleton(module1), ContainerUtilRt.newHashSet(configuration.getModules())); } finally { Disposer.dispose(editor); } }
public void testExternalizeJUnitConfiguration() throws WriteExternalException, InvalidDataException { JUnitConfiguration configuration = createConfiguration(findTestA(getModule1())); Element element = new Element("cfg"); configuration.writeExternal(element); JUnitConfiguration newCfg = new JUnitConfiguration( null, myProject, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]); newCfg.readExternal(element); checkTestObject(configuration.getPersistentData().TEST_OBJECT, newCfg); assertEquals( Collections.singleton(getModule1()), ContainerUtilRt.newHashSet(newCfg.getModules())); checkClassName(configuration.getPersistentData().getMainClassName(), newCfg); }
public void testRunAllInPackageWhenPackageIsEmptyInModule() throws ExecutionException { assignJdk(getModule2()); JUnitConfiguration configuration = new JUnitConfiguration( "", myProject, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]); configuration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE; configuration.getPersistentData().PACKAGE_NAME = "test2"; configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT); assertEmpty(configuration.getModules()); checkCanRun(configuration); configuration.getPersistentData().PACKAGE_NAME = "noTests"; // checkCantRun(configuration, "No tests found in the package '"); configuration.getPersistentData().PACKAGE_NAME = "com.abcent"; checkCantRun(configuration, "Package 'com.abcent' not found"); }
public void testAllInPackageForCommonAncestorModule() throws IOException, ExecutionException { disposeModule(getModule2()); addModule("module5", true); Module ancestor = getModule1(); Module child1 = getModule2(); Module child2 = getModule3(); addDependency(ancestor, child1); addDependency(ancestor, child2); PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage("test1"); JUnitConfiguration configuration = createJUnitConfiguration( psiPackage, AllInPackageConfigurationProducer.class, new MapDataContext()); configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT); assertNotNull(configuration); checkPackage(psiPackage.getQualifiedName(), configuration); assertEmpty(configuration.getModules()); JavaParameters parameters = checkCanRun(configuration); List<String> tests = extractAllInPackageTests(parameters, psiPackage); String childTest1 = findClass(child1, "test1.TestB").getQualifiedName(); String childTest2 = findClass(child2, "test1.Test5").getQualifiedName(); String ancestorTest = findClass(ancestor, "test1.TestA").getQualifiedName(); CHECK.containsAll(tests, new Object[] {ancestorTest, childTest1, childTest2}); }
public SourceScope getSourceScope() { return SourceScope.modulesWithDependencies(myConfiguration.getModules()); }