Android Instrumentation Tests when ran are giving error "EarlySingletonComponentCreatorImpl is not abstract" - dagger-hilt

When running instrumentation tests on Android Studio , seeing below error.
EarlySingletonComponentCreatorImpl is not abstract and does not override abstract method create() in EarlySingletonComponentCreator
class EarlySingletonComponentCreatorImpl extends EarlySingletonComponentCreator {
^
Using the below version of hilt. Can someone please help.
hilt : 2.41
hilt_jetpack = "1.0.0"
hilt_compiler = "1.0.0"

Related

Test containing $this->expectsEvents() always passes

The following test always passes in my Laravel 5.2 app upgraded from 5.1:
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class EventTest extends TestCase
{
public function tearDown()
{
Mockery::close();
}
public function testExample()
{
$this->expectsEvents(App\Events\Foo::class);
}
}
This is despite the App\Events\Foo class not even existing. I've tested the same test in a fresh 5.2 install and it fails as expected. I've looked over the upgrade guide and all relevant non-core code to see whether there's something I've missed that's changed between 5.1 and 5.2 but I can't figure it out. Any ideas?
You need to execute parent tearDown method:
public function tearDown()
{
Mockery::close();
parent::tearDown();
}

Play Framework 2.2 Ebean dependencies?

I'm in the process of migrating from Play Framework 2.1.5 to 2.2.6. I was having tons of errors like this:
[error] C:\dev\CS\trunk\app\models\Asset.java:57: error: cannot find symbol
[error] #NotNull
[error] ^
[error] symbol: class NotNull
[error] location: class Asset
and this:
play.PlayExceptions$CompilationException: Compilation error[error: package com.avaje.ebean.validation does not exist]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:304) ~[na:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:298) ~[na:na]
I have found online in this thread that I needed to add a line in my dependencies to make it work.
"org.avaje.ebeanorm" % "avaje-ebeanorm-api" % "3.1.1",
I have multiple question about this:
1. Why is another import needed for Ebean? I have imported the javaEbean, shouldn't it be enough to be up and running? It was ok 2.1.5 and nothing point to that in the migration documentation.
2. When I look at this package, it seems to be used by nobody. Should I be using something else? Is this some kind of deprecated package?
3. The main reason I ask all of these questions is because, even if it work to resolve these dependencies on my dev machine (windows), when deploying on the server (unix), it doesn't download the same "sub-dependencies" and it doesn't work at runtime. All of the log point to this library causing trouble...
Thanks!
I have found my answer but it was a long journey, let's begin:
First, Ebean is a complete other project than Play Framework and between Play Framework 2.1 and Play Framework 2.2, the version from Ebean changed from 3.1.2 to 3.2.2. I could not found any release note or documentation but I have found a post from the author in a google group discussion that stated clearly that he deleted the validation from the Ebean library because people should use JSR 303 bean validation instead. Since Ebean is a one man show, the decision seems final.
The problem with that is that the library that provide this said bean validation (javax for example) are not called when doing an update() or a save() which is a regression in our code.
After numerous reading and testing, we have finally created a BaseModel based on Model that override the save() and update() method by calling a validator manully, like this:
#MappedSuperclass
public class BaseModel extends Model {
#Override
public void save() {
Set<ConstraintViolation<BaseModel>> constraints = validate();
if (constraints.size() > 0 ) {
onFoundConstraints(constraints);
} else {
super.save();
}
}
#Override
public void update() {
Set<ConstraintViolation<BaseModel>> constraints = validate();
if (constraints.size() > 0 ) {
onFoundConstraints(constraints);
} else {
super.update();
}
}
private Set<ConstraintViolation<BaseModel>> validate() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
return validator.validate(this);
}
private void onFoundConstraints(Set<ConstraintViolation<BaseModel>> constraints) {
String allErrors = "";
for (ConstraintViolation<BaseModel> constraint : constraints) {
allErrors += constraint.getRootBeanClass().getSimpleName()+
"." + constraint.getPropertyPath() + " " + constraint.getMessage();
}
throw new RuntimeException(allErrors);
}
}
All our object now extends this class and it work well so far. I don't know if the previous validation was doing anything more than that but for our needs, it is ok.
I hope it help others since the Play Framework migration documentation doesn't even talk about this...

Mvvmcross Testing different view models fails when running together

I've come across an interesting error. I have two test files for my xamarin mobile application, both testing view models:
public class TestFirstViewModel : MvxIoCSupportingTest
{
public void AdditionalSetup() {
//Register services and dependencies here.
}
[Fact]
public TestMethod1() {
// Successful test code here.
}
}
That's in one file. In another file, I have:
public class TestSecondViewModel : MvxIoCSupportingTest
{
public void AdditionalSetup() {
//Register services and dependencies here, slightly different from first
}
[Fact]
public TestMethod2() {
// Successful test code here.
}
}
When I run these files individually (I'm using xunit), they work just fine. However, when I run them together, I get the following error on one of the test cases:
Result Message: Cirrious.CrossCore.Exceptions.MvxException : You cannot create more than one instance of MvxSingleton
Result StackTrace:
at Cirrious.CrossCore.Core.MvxSingleton`1..ctor()
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer..ctor(IMvxIocOptions options)
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Initialize(IMvxIocOptions options)
at Cirrious.MvvmCross.Test.Core.MvxIoCSupportingTest.ClearAll()
at Cirrious.MvvmCross.Test.Core.MvxIoCSupportingTest.Setup()
at Project.Test.TestFirstViewModel.TestMethod1() in ...
Can anyone tell me what's going on here?
The issue stems from the parallelization of XUnit without the option to do proper tear-down. You could diable parallelization in the AssemblyIndo.cs file in you test project by adding:
[assembly: CollectionBehavior(DisableTestParallelization = true)]
I ended up solving this question by changing testing frameworks. I had different ioc singleton initializations, because, well, they're different test cases and needed different inputs/mocks. Instead of using Xunit, I resorted to Nunit where their cache clearing was much more defined: Xunit doesn't exactly believe in setup and tear-down, so it made a test environment like this more difficult.
I fixed the issue by using the collection attribute.
[Collection("ViewModels")]
class ViewModelATest : BaseViewModelTest {
...
}
[Collection("ViewModels")]
class ViewModelBTest : BaseViewModelTest {
...
}
The base view model test class has the mock dispatcher and performs the singleton registrations in the additional setup method.
Each of my tests calls ClearAll() at the beginning.
I hade some success with setup things in a constructor and add this check:
public PaymentRepositoryTests()
{
if (MvxSingletonCache.Instance == null)
{
Setup();
}
//other registerings.
}`
Also I did implement the IDisposable Interface
public void Dispose()
{
ClearAll();
}
But tbh not sure how much impact that had..
It works ok with xunit
Copy MvxIocSupportingTest and Mvxtest in your xunit PCL project.
Modify MvxTest to remove the attributes and use a simple contructor:
public class MvxTest : MvxIoCSupportingTest
{
protected MockMvxViewDispatcher MockDispatcher { get; private set; }
public MvxTest()
{
Setup();
}
...
And in each of you test, derive from IClassFixture
public class TestRadiosApi : IClassFixture<MvxTest>
{
[Fact]
public async Task TestToken()
{
...
xunit will create the MvxTest class only once for all tests.

NullpointerException: cannot get property on null object

Working on IDEA and trying to launch the following code:
package com.myCompany.routing.spring
import com.dropbox.core.DbxRequestConfig
import grails.util.Holders
import spock.lang.Specification
class DropboxSpringConfigSpec extends Specification {
def grailsApplication=Holders.grailsApplication
def "It instantiates and configures the dropboxRequestConfig component"() {
given:
def ctx = grailsApplication.mainContext
//do stuff...
}
}
I get the following error:
java.lang.NullPointerException: Cannot get property 'mainContext' on null object
at com.myCompany.routing.spring.DropboxSpringConfigSpec.It instantiates and configures the dropboxRequestConfig component(DropboxSpringConfigSpec.groovy:20)
I've recently made a pull on my VCS, so the code should work.
When running the test as Grails test, I get the following error:
Error |
2015-03-04 13:32:00,989 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application:
Missing configuration in Config.groovy: connection.uri.
Okay, it seems some configurations in Config.groovy were given the values of some environment variables:
elasticSearch {
connection {
uri = env.ES_URL
username = env.ES_USER
password = env.ES_PASSWORD
}
indexPrefix = 'test-'
}
Since I never created the corresponding environment variables, the GrailsContextLoader fails to find the corresponding value and the computation fail.
Initializing the required environmnent variables in my IDE and running the tests as Grails tests solved the problem.
By your extends Specification seems that what you have there is a unit test. grailsApplication is not available on unit specs, though it can be mocked (ie. using the #TestFor(ClassUnderTest) annotation mockes it up for you).
If what you want to test is configuration I would recommend writing an integration spec. On the integration phase, you basically have a wired grails application without the web interface. In that case all you'll need would be to do is
package com.myCompany.routing.spring
import com.dropbox.core.DbxRequestConfig
import grails.util.Holders
import grails.test.spock.IntegrationSpec
class DropboxSpringConfigSpec extends IntegrationSpec {
def grailsApplication //This will be auto-wired
def "It instantiates and configures the dropboxRequestConfig component"() {
given:
def ctx = grailsApplication.mainContext
//do stuff...
}
}
Re that test having worked previously in your VCS. I've never used Holders on a unit spec, so I cannot really say it wouldn't work, but it may have just been a false positive. From my understanding on the unit phase you don't have a running grails application and beans (including config) would not be available until mocked by you or the testing framework (again, using #TestFor or #Mock)

Robospice Impossible to start SpiceManager as no service of class

I am trying to use following libraries to develop my app.
Robospice
Gson
and Spring for android
To do so, In my gradle file I have following dependencies added
compile 'com.octo.android.robospice:robospice-spring-android:1.4.13'
compile 'com.google.code.gson:gson:2.2.4'
And in manifest file, I have following lines inserted inside application tag.
<service
android:name="com.octo.android.robospice.GsonSpringAndroidSpiceService"
android:exported="false" />
Now, I created a base class that is used as Base Activity. And, I have did this in the following way:
public class BaseSpiceActivity extends Activity {
private SpiceManager spiceManager = new SpiceManager(GsonSpringAndroidSpiceService.class);
#Override
protected void onStart() {
spiceManager.start(this);
super.onStart();
}
#Override
protected void onStop() {
spiceManager.shouldStop();
super.onStop();
}
protected SpiceManager getSpiceManager() {
return spiceManager;
}
}
And then I used that base class to extend my own class where I had to use spice service request.
SimpleTextRequest text = new SimpleTextRequest(placeUrl);
getSpiceManager().execute(text, "place", DurationInMillis.ONE_MINUTE, new RequestListener<String>() {
//Other functions and codes
}
)
But when the above code gets executed, I am getting following error
E/AndroidRuntime﹕ FATAL EXCEPTION: SpiceManagerThread 0
java.lang.RuntimeException: Impossible to start SpiceManager as no service of class : com.octo.android.robospice.SpiceService is registered in AndroidManifest.xml file !
at com.octo.android.robospice.SpiceManager.checkServiceIsProperlyDeclaredInAndroidManifest(SpiceManager.java:1287)
at com.octo.android.robospice.SpiceManager.tryToStartService(SpiceManager.java:1168)
at com.octo.android.robospice.SpiceManager.run(SpiceManager.java:247)
at java.lang.Thread.run(Thread.java:856)
I have been trying to solve the issue from many hours. But unfortunately couldn't. Please help me out.
I am 100% sure you got messed somewhere. Search for new SpiceManager(SpiceService.class); in your code, and you will find out that you do use this service instead of the desired GsonSpringAndroidSpiceService.
You need to declare your service in your manifest.xml
Like this
<service android:name=".SampleRetrofitService"
android:exported="false"/>
Try to find out where using SpiceManager.
In my case, I named a activity SpiceActivity, and others extend it.
But robospice library also offer a activity named SpiceActivity. And it uses new SpiceManager(SpiceService.class)
So activity extends the wrong SpiceActivity which use SpiceService, then cause the error.

Resources