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 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 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); }
@Override public boolean isConfigurationFromContext( JUnitConfiguration unitConfiguration, ConfigurationContext context) { if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class) .isMultipleElementsSelected(context)) { return false; } final RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(JUnitConfigurationType.getInstance()); final Location contextLocation = context.getLocation(); String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null; assert contextLocation != null; Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation); if (location == null) { return false; } final PsiElement element = location.getPsiElement(); final PsiClass testClass = JUnitUtil.getTestClass(element); final PsiMethod testMethod = JUnitUtil.getTestMethod(element, false); final PsiPackage testPackage; if (element instanceof PsiPackage) { testPackage = (PsiPackage) element; } else if (element instanceof PsiDirectory) { testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element)); } else { testPackage = null; } PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null; RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()) .getConfigurationTemplate(getConfigurationFactory()); final Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule(); final String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null; if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) return false; if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) return false; final TestObject testobject = unitConfiguration.getTestObject(); if (testobject != null) { if (testobject.isConfiguredByElement( unitConfiguration, testClass, testMethod, testPackage, testDir)) { final Module configurationModule = unitConfiguration.getConfigurationModule().getModule(); if (Comparing.equal(location.getModule(), configurationModule)) return true; if (Comparing.equal(predefinedModule, configurationModule)) { return true; } } } return false; }
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 boolean isConfiguredByElement( final JUnitConfiguration configuration, PsiClass testClass, PsiMethod testMethod, PsiPackage testPackage) { return testPackage != null && Comparing.equal( testPackage.getQualifiedName(), configuration.getPersistentData().getPackageName()); }
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"); }