简体   繁体   中英

Intellij IDEA Doesn't See Tests (java.lang.Exception: No tests found in class)

Friends,

My IDEA refuses to see tests and barks out:

 java.lang.Exception: No tests found in class
at com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner.runViaRestCall(AtlassianPluginsTestRunner.java:125)
    at com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner.run(AtlassianPluginsTestRunner.java:75)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

 

I have already tried the following:

  • Rebuilding and restarting IDEA
  • Cleaning the project
  • Changing the name of the test
  • Set up "Build project" instead of just "Build" in the settings of the method's launch

Any idea what I can try else?

Here is the code:

atlassian.plugins.osgi.test.AtlassianPluginsTestRunner;
import com.atlassian.query.Query;
import com.idalko.jira.plugins.igrid.grid.JiraCompatibilityHandler;
import com.idalko.jira.plugins.igrid.rest.api.ApiResource;
import com.idalko.jira.plugins.igrid.services.FileResourceService;
import com.idalko.jira.plugins.igrid.services.SQLExecutor;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * Created by strygul on 3/23/17.
 */
@RunWith(AtlassianPluginsTestRunner.class)
public class GridSearchWiredTest {
    public static final Logger LOG = Logger.getLogger(ApiResource.class);
    private SearchService searchService;
    private JiraCompatibilityHandler jiraCompatibilityHandler;
    private final String SQL_BEFORE_FILE_PATH = "testcases/grid_search/before.sql";
    private final String BACKUP_PATH = "jira-default-backup.zip";
    private final String[] ZIP_EXTENSION = new String[]{"zip"};
    private FileResourceService fileResourceService;
    private SQLExecutor sqlExecutor;
    public static final String DEFAULT_GRID_NAME = "GridSearchJiraCase_Grid";

//    public GridSearchWiredTest(SearchService searchService, JiraCompatibilityHandler jiraCompatibilityHandler) {
//        this.searchService = searchService;
//        this.jiraCompatibilityHandler = jiraCompatibilityHandler;
//        this.fileResourceService = new FileResourceService();
//        this.sqlExecutor = new SQLExecutorImpl(fileResourceService);
//    }

    @Before
    public void setUp() throws Exception {
        restoreJiraData();
        executeSql();
    }

    @Test
    public void testSomething() {
        JqlQueryBuilder osGiComponentInstanceOfType = ComponentAccessor.getOSGiComponentInstanceOfType(JqlQueryBuilder.class);
        Query query = osGiComponentInstanceOfType.newBuilder().where().addFunctionCondition("issue", "grid", DEFAULT_GRID_NAME, "astring like 'test string 1'").buildQuery();
        SearchResults results = jiraCompatibilityHandler.search(query, PagerFilter.getUnlimitedFilter());
        List<Issue> issues = results.getIssues();
        assertEquals(2, issues.size());
    }

    private void executeSql() throws URISyntaxException, IOException {
        File sqlFile = fileResourceService.getFile(SQL_BEFORE_FILE_PATH);
        sqlExecutor.executeSQL(sqlFile);
    }

    private void restoreJiraData() {
        if(needToRestoreJira()) {
            RestoreJiraData restoreJiraData = new SmartRestoreJiraData();
            restoreJiraData.restore(BACKUP_PATH);
        }
    }

    protected boolean needToRestoreJira() {
        final String importFolder = "jira" + File.separator + "home" + File.separator + "import";
        final File root;
        try {
            root = fileResourceService.getFile("").getParentFile();
        } catch (URISyntaxException e) {
            return false;
        }
        return FileUtils.listFiles(new File(root, importFolder), ZIP_EXTENSION, false).isEmpty();
    }
}

Ok, I figured out what was the problem.

It was a problem neither with Intellij, nor with JUnit. The problem was in OSGI. I forgot to add a class from my plugin to my Test plugin's import. As the consequence, it failed to build the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM