public void testEditJUnitConfiguration() throws ConfigurationException { if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return; PsiClass testA = findTestA(getModule2()); JUnitConfiguration configuration = createConfiguration(testA); JUnitConfigurable editor = new JUnitConfigurable(myProject); try { Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration); configurable.reset(); final EditorTextFieldWithBrowseButton component = ((LabeledComponent<EditorTextFieldWithBrowseButton>) editor.getTestLocation(JUnitConfigurationModel.CLASS)) .getComponent(); assertEquals(testA.getQualifiedName(), component.getText()); PsiClass otherTest = findClass(getModule2(), "test2.Test2"); component.setText(otherTest.getQualifiedName()); configurable.apply(); assertEquals(otherTest.getName(), configuration.getName()); String specialName = "My name"; configuration.setName(specialName); configuration.setNameChangedByUser(true); configurable.reset(); component.setText(testA.getQualifiedName()); configurable.apply(); assertEquals(specialName, configuration.getName()); } finally { Disposer.dispose(editor); } }
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 testAllInPackageForProject() throws IOException, ExecutionException { // module1 -> module2 -> module3 // module5 addModule("module5"); addDependency(getModule1(), getModule2()); addDependency(getModule2(), getModule3()); String[][] outputs = new String[4][]; for (int i = 0; i < 4; i++) { outputs[i] = addOutputs(getModule(i), i + 1); } PsiPackage defaultPackage = JavaPsiFacade.getInstance(myProject).findPackage(""); JUnitConfiguration configuration = createJUnitConfiguration( defaultPackage, AllInPackageConfigurationProducer.class, new MapDataContext()); configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT); JavaParameters javaParameters = checkCanRun(configuration); String classPath = javaParameters.getClassPath().getPathsString(); assertEquals(-1, classPath.indexOf(JarFileSystem.PROTOCOL_PREFIX)); assertEquals(-1, classPath.indexOf(LocalFileSystem.PROTOCOL_PREFIX)); for (int i = 0; i < 4; i++) { checkContains(classPath, outputs[i][0]); checkContains(classPath, outputs[i][1]); } }
public void testTestClassPathWhenRunningConfigurations() throws IOException, ExecutionException { addModule("module4", false); Module module4 = getModule4(); assignJdk(module4); addSourcePath(module4, "testSrc", true); addSourcePath(module4, "src", false); String output = setCompilerOutput(module4, "classes", false); String testOuput = setCompilerOutput(module4, "testClasses", true); ApplicationConfiguration applicationConfiguration = createConfiguration(findClass(module4, "Application")); JavaParameters parameters = checkCanRun(applicationConfiguration); String classPath = parameters.getClassPath().getPathsString(); checkDoesNotContain(classPath, testOuput); checkContains(classPath, output); JUnitConfiguration junitConfiguration = createJUnitConfiguration( findClass(module4, "TestApplication"), TestClassConfigurationProducer.class, new MapDataContext()); parameters = checkCanRun(junitConfiguration); classPath = parameters.getClassPath().getPathsString(); checkContains(classPath, testOuput); checkContains(classPath, output); applicationConfiguration.MAIN_CLASS_NAME = junitConfiguration.getPersistentData().getMainClassName(); classPath = checkCanRun(applicationConfiguration).getClassPath().getPathsString(); checkContains(classPath, testOuput); checkContains(classPath, output); }
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); } }
private JUnitConfiguration createConfiguration(PsiPackage psiPackage, Module module) { JUnitConfiguration configuration = new JUnitConfiguration( "", myProject, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]); configuration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE; configuration.getPersistentData().PACKAGE_NAME = psiPackage.getQualifiedName(); configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT); configuration.setModule(module); return configuration; }
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 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"); }