Home > Blockchain >  Java - Need to Conditionally enable a Unit test dependent on whether the device is a Mac M1
Java - Need to Conditionally enable a Unit test dependent on whether the device is a Mac M1

Time:11-21

I need to enable a test whenever the system running the test is not an m1 mac.

Struggling to find a way to identify when the device is an m1

CodePudding user response:

In Java you can get informations about the system running the JVM using the following:

 //Operating system name
 System.out.println("Your OS name -> "   System.getProperty("os.name"));

 //Operating system version
 System.out.println("Your OS version -> "   System.getProperty("os.version"));

 //Operating system architecture
 System.out.println("Your OS Architecture -> "   System.getProperty("os.arch"));

So you should build your logics around the last method, the returned values are Strings.

On your M1 Mac you should get an output like this:

Your OS Architecture -> aarch64
  • Related