flutter test fails. compiler error getter not found 'main'
Solution 1
In my case, it happened that one of my helper classes in the test folder, had a name that ended "_test", and the compiler was looking for a main method. So I renamed the helper class, and problem solved.
Solution 2
If anybody faces the above problem then try to add main()
in test class and if you have added then remove it out of test class curly braces. I faced this and removed the main()
out of test class.
Eg...
class GetConcreteNumberTrivia_Test extends Mock
implements NumberTriviaRepository {}
void main() {
.....my implementation......
}
Solution 3
It seems this error can have a lot of different causes. In my case the problem was a file foo_test.dart
with the only content //TODO
. So it was basically empty and the compiler could not find the excpected main method. The weird thing was, that it threw the Error in another test!
When I removed foo_test.dart
, it worked again! Hope this helps!
Solution 4
I had this error when a merge mess put the main() within a class.
Solution 5
I also got this error. My problem has been how I named the files for my tests. The test runner is looking for this pattern "*_test.dart" (hier). After renaming my test files accordingly, the test runner executes the test without any errors.
Salma
Updated on December 11, 2022Comments
-
Salma over 1 year
I'm trying to run flutter test using the terminal and i receive the following error. the following file C:/Users/User/AppData/Local/Temp/flutter_test_listener.e6fa92b4-6cd1-11e9-b9cb-68f728ca4610/listener.dart doesn't exist in the directory specified.
here's the error:
Compiler message: file:///C:/Users/User-45/AppData/Local/Temp/flutter_test_listener.e6fa92b4-6cd1-11e9-b9cb-68f728ca4610/listener.dart:46:17:
Error:Getter not found: 'main'. return test.main;
my project's directory is in another folder. how can i solve this? Thank you