Я получаю следующую ошибку, когда я запускаю свои тесты в Jenkins. Они отлично работают в Eclipse.
junit.framework.AssertionFailedError: No tests found in SCSystemTestCase
SCSystemTestCase - это класс, который расширяет TestCase и используется другими Junit Tests для запуска тестов. Сниппет SCSystemTestCase показан ниже
import java.io.File;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Vector;
import junit.framework.TestCase;
import junit.framework.AssertionFailedError;
import org.jtestcase.JTestCase;
import org.jtestcase.JTestCaseException;
import org.jtestcase.TestCaseInstance;
import org.junit.Test;
public class SCSystemTestCase extends TestCase
{
protected HashMap<String, Vector<String>> params = null;
protected String testCaseFName = "";
protected String testGoal = "";
protected String testCaseFFolder = "";
protected String testCaseClass = "";
protected String testCaseLocationprefix = "SC";
protected String testCaseLocation = "";
protected String jerseyEndpoint = "";
protected String requestMethod = "";
protected String requestPath = "";
protected String responseData = "";
protected String description = "";
protected String dataDir = "";
protected String testCaseName;
protected String testCaseMethod;
protected TestCaseInstance testCaseCur;
protected Vector<?> testCases = null;
private JTestCase thisJtestCase;
public SCSystemTestCase(String s, String t)
{
super(s);
testCaseName = s;
testCaseMethod = t;
}
public SCSystemTestCase(String s)
{
super(s);
}
public SCSystemTestCase()
{
}
public void setup() throws Exception
{
try
{
testCaseLocation = testCaseFFolder + File.separator + testCaseFName;
setThisJtestCase(new JTestCase(testCaseLocation, testCaseClass));
}
catch (JTestCaseException jte)
{
System.out.println(jte.getMessage());
}
}
@Override
protected void runTest() throws Throwable
{
setup();
triggerTest();
}
@Test
protected void triggerTest() throws Exception
{
StringBuffer errorBucket = new StringBuffer();
Hashtable<?,?> globalParams = null;
// Hashtable<String, String> globalParams = null;
try
{
testCases = getThisJtestCase().getTestCasesInstancesInMethod(testCaseMethod);
globalParams = getThisJtestCase().getGlobalParams();
jerseyEndpoint = (String) globalParams.get("jerseyEndpoint");
requestMethod = (String) globalParams.get("requestMethod");
requestPath = (String) globalParams.get("requestPath");
dataDir = (String) globalParams.get("dataDir");
for (int i = 0; i < testCases.size(); i++)
{
testCaseCur = (TestCaseInstance) testCases.elementAt(i);
if (testCaseCur.getTestCaseName().equals(testCaseName))
{
System.out.println("Starting test: " + testCaseCur.getTestCaseName());
System.out.println("======================================================");
params = testCaseCur.getTestCaseParams();
testGoal = (String) ((params.get("testGoal") != null) ? params.get("testGoal") : " Not Specified ");
System.out.println("TEST-GOAL: " + testGoal);
boolean isNegative = (Boolean) ((params.get("isNegative") != null) ? params.get("isNegative") : false);
try
{
XMLDataParser test = new XMLDataParser();
test.testExecuteTestSteps(params);
}
catch (Throwable t)
{
t.printStackTrace();
if (!isNegative)
{
System.out.println("It is NOT a negative test, why did it throw an Exception!");
errorBucket.append("\n-----" + testCaseMethod + "." + testCaseCur.getTestCaseName() + "-----");
errorBucket.append("\nIt is NOT a negative test, why did it throw an Exception!\n");
}
else
{
System.out.println("It is a negative test!");
}
}
finally
{
System.out.println("--Ending test: " + testCaseCur.getTestCaseName() + "--");
}
}
}
}
catch (Throwable t)
{
t.printStackTrace();
}
finally
{
System.out.println("======================================================");
}
if (errorBucket.length() > 0)
{
throw new AssertionFailedError(errorBucket.toString());
}
}
// protected abstract void testExecuteTestSteps() throws Exception, Throwable;
public JTestCase getThisJtestCase()
{
return thisJtestCase;
}
public void setThisJtestCase(JTestCase thisJtestCase)
{
this.thisJtestCase = thisJtestCase;
}
Не могли бы вы помочь мне решить эту проблему? Этот класс не имеет собственного TestSuite() или тестов. Файл build.gradle и eclipse используют Junit4.10. В любом из тестов, которые расширяют это, нет аннотаций @Test. Мне нужно изменить версию junit в файле gradle на junit 3? Если да, какую версию я должен использовать?
Вы смешиваете JUnit 3 и JUnit 4. Я думаю, что Eclipse решит запустить ваш тест как тест JUnit 4, а Gradle решит, что это тест JUnit 3. Это и есть причина различного поведения.
Если вы хотите использовать JUnit 3, вам нужно изменить SCSystemTestCase
setup
метода как setUp
runTest
(его нельзя переопределять в соответствии с его Javadoc)@Test
triggerTest
как testSomething
(важно, чтобы имя метода triggerTest
с test
).org.junit
или один из его org.junit
. Но я настоятельно рекомендую использовать JUnit 4. Для этого вам нужно изменить SCSystemTestCase
extends TestCase
часть extends TestCase
вашего объявления классаsuper
в ваших конструкторахrunTest
.SCSystemTestCase
) должен иметь конструктор по умолчанию (конструктор без аргументов)junit.framework
или один из его junit.framework
.