My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label plugin. Show all posts
Showing posts with label plugin. Show all posts

Monday, November 30, 2020

Mockito MockMaker Java IllegalStateException Error: How to Fix Mockito Plugin error in Testing

 There are times when you will land into problems while running Mock tests using Mockito. A Sample error could be like:

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker


The issue is that the Mockito core depends on a library called byte-buddy and this problem is mostly occurred when mockito doesn’t find a matching byte buddy jar version.

Error screenshot:


To Solve this issue find out the mockito core version your project is using.

In eclipse, you can check in project build path by navigating as follows:

Right click on project -> Properties -> Java build path -> Libraries tab


For IntelliJ This could be different. Look the screenshot below:



Search maven repository for that version of mockito core. To me, it was : https://mvnrepository.com/artifact/org.mockito/mockito-core/2.7.1



Description of issue:

The actual issue it seems is because of error from ByteBuddyAgent. I found following stacktraces that pointed me to the error:

Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@e32787d

at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:316)

at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<clinit>(InlineByteBuddyMockMaker.java:102)

... 34 more

Caused by: java.lang.reflect.InvocationTargetException

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:303)


Solution to fix the error:

Look at the Compile Dependencies section. Note down the correct dependent version of byte-buddy and include in the project. If the jar is already included with some other version, override the version with this correct version.

Also, i did see following in stacktrace:

[ERROR] error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /modules/java.base/java/lang/Object.class


So, fix above two issues. Build the application and run the tests again. Your issue related to MockMaker must be solved by now.

Voila :)

Enjoy!


Monday, April 13, 2020

maven surefire plugin runtime exception - writing xml report stdout/stderr

Problem: Sometimes you get the RunTime exception in your java projects. Example in an enterprise spring boot application when you use:

> mvn clean install
or, mvn package


See the error snapshot below:

Tests run: 325, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  24:49 min
[INFO] Finished at: 2020-04-13T13:25:50+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project postbooking-ndc-pad: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: java.lang.RuntimeException: org.apache.maven.surefire.report.ReporterException: When writing xml report stdout/stderr: /var/folders/3r/wl3bcq6x0cq1_zxj94xtz6ww0000gn/T/stdout8283814721678605256deferred (No such file or directory) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException


Root cause:

This mainly happens because of using wrong/ old version of suefire in your pom.xml while some parts of your code requires higher versions in compilation.


Possible remediation:

1. Either ignore tests while building
>mvn install -DskipTests

2. or,  use latest Surefire in pom.xml 2.22.0


Friday, January 31, 2020

Build using Maven - MVN and POM.xml

In order to build a Maven project you can use one of the following:

  • mvn clean install
  • mvn clean package etc.

This would build/compile and run the tests as well.

However, if you want to run the tests only then what would you do?

Sound similar? Yeah! we all often land up in this situation as an application developer. And, the solution is simple.


You can use mvn test to run unit test in Maven. Few examples :
# Run all the unit test classes.
$ mvn test

# Run a single test class.
$ mvn -Dtest=TestApp1 test

# Run multiple test classes.
$ mvn -Dtest=TestApp1,TestApp2 test

# Run a single test method from a test class.
$ mvn -Dtest=TestApp1#methodname test

# Run all test methods that match pattern 'testHello*' from a test class.
$ mvn -Dtest=TestApp1#testHello* test

# Run all test methods match pattern 'testHello*' and 'testMagic*' from a test class.
$ mvn -Dtest=TestApp1#testHello*+testMagic* test

The default maven-surefire-plugin is outdated, make sure update to the latest to support new features, like pattern matching or run a single test method, and etc.
pom.xml
 <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
            </plugin>

        </plugins>
    </build>

Friday, November 17, 2017

Difference between Nuget and Chocolatey

NuGet is designed to allow you to easily add code libraries to your project. Things like JSON.NET, Entity Framework, etc.


Chocolatey is actually built on top of the NuGet package system, but it is designed to fill a different need. Chocolatey wraps up applications and other executables and makes it easy to install them on your computer. For example, tools like Git and Notepad++, etc. can be easily installed with a command like: cinst git.


To know more about chocolate and how to install it please refer my earlier blog post on W3LC : http://www.w3lc.com/2017/11/what-is-chocolatey-and-how-to-install.html


https://chocolatey.org/packages has a list of all the applications that can be installed.


If you have an open source project which is a library that is to be used in other developers' projects, then you should submit it to NuGet.


If it is an application that users would normally install, then create a Chocolatey package that users can easily install and update from the command line.


Details of different Package manager tools and where does Chocolate fits in:


OneGet has been renamed to Package management. It's core provides you with discovery and installation/uninstallation of various packages. OneGet is often referred to as a "package manager manager".

OneGet is a part of WMF 5 installation. Think of this as the "central concept" in the big picture. Now let's talk about packages.

Packages are fetched through package providers. E.g. PowerShellGet is one package provider for OneGet. Powershell gallery is a package source of of PowershellGet (PSGet). A provider can have multiple sources where it can search for it's packages.

E.g for the nuget-package provider; you can easily add the sources to the public nuget gallery and register your own e.g. myget source so it can be used when searching for packages.

Chocolatey is just another example of a package provider. Earlier it had to be installed and was a seperate module with it's own logic. The new Chocolatey provider conforms to the new framework of installing / managing packages.

So on a more conceptual level; a package provider itself contains information on how to install and search it's sources (sources can be registered/unregistered for each and every provider); whilst OneGet (Package management, package manager manager) works on the level above, managing package providers and interfacing this all for you.

OneGet glues it all together; while the providers itself knows how to handle packages based on it's registered sources.

Hope this explains it on the conceptual level.

See also this nice blogpost here explaining a few things more in detail:https://blogs.technet.microsoft.com/packagemanagement/2015/05/05/10-things-about-oneget-that-are-completely-different-than-you-think/

If you want to play around with package providers and sources :

 Get-PackageProvider # -Shows package providers installed on your machine)
 Find-PackageProvider # -Find online package providers you can pull down and install)
 Get-PackageSource # -List all package sources, with it's provider name)
 Register-PackageSource # -Register new package source for a provider)