Android junit framework assertionfailederror no tests found in

Получение junit.framework.AssertionFailedError: тестов, найденных в при использовании Unit и Mockito

Я добавил следующие зависимости к моему проекту для Android:

И создать тест с помощью junit4 api (пример, Adder – это простой класс, который суммирует ints):

Когда я пытаюсь запустить тест, я получаю:

Запуск тестов Запуск теста запущен junit.framework.AssertionFailedError: тестов нет в com.test.myapp.AdderTest на android.test.AndroidTestRunner.runTest (AndroidTestRunner.java:191) на android.test.AndroidTestRunner.runTest (AndroidTestRunner.java: 176) на android.test.InstrumentationTestRunner.onStart (InstrumentationTestRunner.java:554) на android.app.Инструментация $ InstrumentationThread.run (Instrumentation.java:1701) Готово

Я читаю здесь и здесь , но ничего не помогает.

Кто-нибудь видит, что я делаю неправильно / имеет какой-либо вклад?

Это не модульные тесты, они являются контрольно-измерительным тестом. У меня была такая же проблема, и я решил ее, добавив эти строки в build.radry:

Вы должны добавить бегун в зависимости, я предлагаю вам эспрессо:

РЕДАКТИРОВАТЬ:

Я забыл об аннотации. Просто удалите @RunWith и создайте метод @Before с помощью строки:

Я должен упомянуть об этом, поэтому не рекомендуется. Чтобы использовать второй, вам нужно добавить зависимости с dex-maker для mockito:

Поскольку вы добавили mockito, мы должны исключить ядро ​​mockito из новой зависимости. Он уже содержит нормальный модуль dex-maker.

Вы используете тест инструментария для Android. По умолчанию тестовый бегун Android не запускается на JUnit4, он работает на JUnit3 с использованием подклассов InstrumentationTestCase .

Вам нужно будет вернуться к ручным вызовам в MockitoAnnotations.initMocks() с дополнительным отрывным вызовом Mockito.validateMockitoUsage() . Конечно, звонки непосредственно в Mockito.mock (и такие) будут по-прежнему работать.

В качестве альтернативы, есть официальный бегун JUnit4 , который можно установить из тестовой библиотеки поддержки Android . Вызывая этот инструмент, а не тестовый бегун по умолчанию, вы можете запускать тесты JUnit4 на вашем устройстве, включая использование MockitoJUnitRunner или MockitoRule .

Читайте также:  Значки андроида вверху экрана samsung galaxy

Источник

why dropped junit.framework.AssertionFailedError? #1326

Comments

Reissner commented Jun 6, 2016

This is more a question but an issue.
In very old junit, AssertionFailedError extends AssertionError was available.
But now Assert throws just AssertionError.
With assertions enabled, failed assertions cannot be distinguished from failed tests.
Isnt this a bug??

The text was updated successfully, but these errors were encountered:

kcooney commented Jun 6, 2016

Believe it or not, JUnit actually predated the assert keyword being added to Java.

I wasn’t involved in the initial creation of JUnit 4.0 but I suspect they decided that creating a new exception wasn’t necessary.

In the end, distinguishing the two doesn’t matter. When tests throw exceptions they fail. The message should make it easy to see why the failure happened.

Reissner commented Jun 6, 2016

Well, I remember the times where one distinguished,
whether a test could not be executed and was thus invalid and did neither pass nor fail
or whether it could be executed but discovered a failure.

With AssertionFailedError being thrown by class Assert,
one cannot distinguish clearly.

kcooney commented Jun 6, 2016

With JUnit4-style tests, if a test can determine that it cannot be executed, then it can use Assume so it isn’t reported as a pass or a fail.

If JUnit cannot run the test for some reason, that shows up as a failure.

To the best of my knowledge, JUnit3-style tests never threw a AssertionFailure that wasn’t an instance of AssertionFailureError , so if you saw those, your tests or code was throwing them.

Reissner commented Jun 6, 2016

Well, AssertionFailedError extended AssertionError, so the fathers of JUnit surely had a notion of assertion. By the way, in the very first draft of the jls assert was forseen, but later dropped.

You write: If JUnit cannot run the test for some reason, that shows up as a failure.
Hm, if a tests fails to execute (originally called ‘test in error’), this does not show a failure in the software tested, right?
It just shows that not all tests forseen for assuring a predefined quality level could be evaluated.
If in contrast a test executes but returns with a failure (originally called ‘test in failure’),
a bug in the application is found.

Thus it is vital to distinguish test in failure and test in error.

Читайте также:  Gens sega emulator android

you write:
‘To the best of my knowledge, JUnit3-style tests never threw a AssertionFailure that wasn’t an instance of AssertionFailureError, so if you saw those, your tests or code was throwing them.’
Right. it threw AssertionFailureError which is a subclass of AssertionError (there is no AssertionFailure)

you write:
‘With JUnit4-style tests, if a test can determine that it cannot be executed, then it can use Assume so it isn’t reported as a pass or a fail.’
Hm, it is not feasable to catch all kinds of exceptions that could be thrown by a test irregularly,
i.e. outside Assert in terms of an assumption.
Thus it is important to provide a mechanism to fail via some throwable
which can be distinguished from the one thrown by Assert.
This was originally done by throwing AssertionFailedError by Assert
and nowhere else.
AssertionFailedError indicated test in failure.
All other Throwables indicated tests in error.

kcooney commented Jun 7, 2016

Thus it is vital to distinguish test in failure and test in error.

Again, I wasn’t there for the original design of JUnit4. From what I understand, David and Kent decided that the distinction between failure and error wasn’t necessary (and possibly confusing) when they designed JUnit4 ten years ago.

This has been the far too late to change this behavior now in the JUnit4 code base. Perhaps you can file a feature request at https://github.com/junit-team/junit5

kcooney commented Jun 7, 2016

Also remember that there are many third-party assertion frameworks and thise frameworks may not want to depend on JUnit classes. These libraries tend to throw AssertionError

Источник

Lily’s Blogs

Fix junit.framework.AssertionFailedError: No tests found

  • 获取链接
  • Facebook
  • Twitter
  • Pinterest
  • 电子邮件
  • 其他应用

I want to run a test ,but errors occurred,

junit.framework.AssertionFailedError: No tests found in

at junit.framework.Assert.fail(Assert.java:50)
at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
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:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Process finished with exit code -1

I fixed the problem by modifying the name of the method.

Источник

«Test events were not received» in Android Studio Artic Fox #83

Comments

gmerinojimenez commented Sep 2, 2021 •

After migrating to Android Studio Artic Fox, when running unit tests from the IDE, it says «Test events were not received»

Here is the output:

I’ve tried with different versions of Gradle and also use Junit4 & Junit5, but I wasn’t able to find a workaround

Читайте также:  Nfs android для чего

Steps to reproduce
Create an empty project in Android Studio, it will create a class called ExampleUnitTest. Try executing that test when mirakle is configured.

IntelliJ
I’ve also reproduced it in IntelliJ IDEA 2021.2.1 with the same STRs

The text was updated successfully, but these errors were encountered:

Adambl4 commented Sep 2, 2021

Hey, thanks for the clear report.
Could you try 1.5.0-RC-1 and let me know does it work

gmerinojimenez commented Sep 2, 2021

Hi @Adambl4, thanks for the answer, tested and still the same.

BTW, my mirakle setup is like this:

Adambl4 commented Sep 2, 2021

Add this line to mirakle_init script and send me the output.

gmerinojimenez commented Sep 2, 2021

Sure, this is the output:

Adambl4 commented Sep 2, 2021

Okay. Could you also add this to mirake config and send me the output of upload and download tasks.

gmerinojimenez commented Sep 2, 2021

This is the full output now:

Adambl4 commented Sep 2, 2021

I’m testing on the same AS version and it works. Let’s try to synchronize our env.

  1. Update Gradle to 7.2
  2. Disable downloadInParallel
  3. Try to run the same test 5 times in sequence.

Could you also do the following:

  1. ssh to remote machine
  2. cd to your project directory
  3. ls that there is mirakle_init_scripts folder with 3 files (ijmapper.gradle, ijresolvers1.gradle, ijtestinit4.gradle) in root of project dir and check they are all not empty ( cat ijmapper.gradle )

gmerinojimenez commented Sep 2, 2021

this is my mirakle script now:

and the three files were there, this is what they have:

/mirakle/TestsInRemote/mirakle_init_scripts]$ cat ijtestinit4.gradle String[] ijTestIncludes = [‘com.gmerino.testsinremote.ExampleUnitTest’] Class abstractTestTaskClass = null try < abstractTestTaskClass = Class.forName("org.gradle.api.tasks.testing.AbstractTestTask") >catch (ClassNotFoundException ex) < // ignore, class not available >gradle.taskGraph.whenReady < taskGraph ->taskGraph.allTasks.each < Task task ->if (task instanceof Test || (abstractTestTaskClass != null && abstractTestTaskClass.isAssignableFrom(task.class))) < try < task.outputs.upToDateWhen < false >String[] strings = [‘*’] if(ijTestIncludes != strings) < def filter = task.getFilter() filter.setIncludePatterns(new String[0]) ijTestIncludes.each()< filter.includeTestsMatching "$» > > > catch (all) < logger.error("", all) >> > > «>

I’ve tried several times and the result is the same, the tests execute successfully, but seems like Android Studio doesn’t get notified and it says that «Test events were not received»

Adambl4 commented Sep 2, 2021

Hmm, still not clear.
Could you also add this to mirakle_init and send the output

Источник

Оцените статью