Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test runner #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<module>protocol</module>
<module>client</module>
<module>server</module>
<module>runner</module>
</modules>

</project>
37 changes: 37 additions & 0 deletions runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#JUnit 4 Runner

This project aims to replace the maven surefire provider for JUnit test execution with RoboVM


##Examples

```java
package org.robovm.samples.helloworld;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robovm.apple.uikit.UITextField;
import org.robovm.apple.uikit.UIView;
import org.robovm.samples.helloworld.viewcontrollers.MyViewController;
import org.robovm.testkit.runner.RoboVMUITestRunner;

import static junit.framework.TestCase.assertTrue;
import static org.robovm.testkit.UITestKit.getChildViewWithPlaceholderText;
import static org.robovm.testkit.UITestKit.setRootView;

@RunWith(RoboVMTestRunner.class)
public class HelloWorldTest
{

@Test
public void testHello() {
String jvm = System.getProperty("java.runtime.name");
assertTrue(jvm, "RoboVM Runtime".equals(jvm));
}
}
```

##Notes

This is still under heavy development and may not work with all IDEs or build environments. Please report
bugs
88 changes: 88 additions & 0 deletions runner/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.robovm</groupId>
<artifactId>robovm-junit-parent</artifactId>
<version>1.5.1-SNAPSHOT</version>
</parent>

<artifactId>robovm-junit-runner</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robovm-rt</artifactId>
</dependency>
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robovm-objc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robovm-junit-protocol</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robovm-junit-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robovm-compiler</artifactId>
</dependency>
<dependency>
<groupId>org.robovm</groupId>
<artifactId>robovm-maven-resolver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<artifactSet>
<includes>
<include>junit:junit</include>
<include>org.robovm:robovm-junit-server</include>
<include>org.robovm:robovm-junit-protocol</include>
<include>org.robovm:robovm-junit-client</include>
</includes>
</artifactSet>
<filters>
<filter>
<excludes>
<exclude>META-INF/NOTICE.txt</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
215 changes: 215 additions & 0 deletions runner/src/main/java/org/robovm/junit/runner/AbstractJ4Runner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
* Copyright (C) 2014 RoboVM AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.robovm.junit.runner;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
import org.robovm.compiler.Version;
import org.robovm.compiler.config.Arch;
import org.robovm.compiler.config.Config;
import org.robovm.compiler.config.OS;
import org.robovm.compiler.log.ConsoleLogger;
import org.robovm.compiler.log.Logger;
import org.robovm.compiler.target.ios.ProvisioningProfile;
import org.robovm.compiler.target.ios.SigningIdentity;
import org.robovm.maven.resolver.RoboVMResolver;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AbstractJ4Runner extends BlockJUnit4ClassRunner {

protected final Class<?> clazz;
protected final static String PROP_LOG_DEBUG = "robovm.test.enableDebugLogging";
protected final static String PROP_SERVER_DEBUG = "robovm.test.enableServerLogging";
protected final static String PROP_OS = "robovm.test.os";
protected final static String PROP_ARCH = "robovm.test.arch";
protected final static String PROP_CONFIG_FILE = "robovm.test.configFile";
protected final static String PROP_PROPERTIES_FILE = "robovm.test.propertiesFile";
protected final static String PROP_IOS_SIGNING_IDENTITY = "robovm.test.iosSignIdentity";
protected final static String PROP_IOS_PROVISIONING_PROFILE = "robovm.test.iosProvisioningProfile";
protected final static String PROP_IOS_SKIP_SIGNING = "robovm.test.iosSkipSigning";

public AbstractJ4Runner(Class<?> clazz) throws InitializationError {
super(clazz);
this.clazz = clazz;
}

protected org.junit.runner.notification.RunListener getRunListener(final RunNotifier runNotifier) {
return new org.junit.runner.notification.RunListener() {
public void testRunStarted(Description description) throws Exception {
runNotifier.fireTestRunStarted(description);
}

public void testRunFinished(Result result) throws Exception {
runNotifier.fireTestRunFinished(result);
}

public void testStarted(Description description) throws Exception {
runNotifier.fireTestStarted(description);
}

public void testFinished(Description description) throws Exception {
runNotifier.fireTestFinished(description);
}

public void testFailure(Failure failure) throws Exception {
runNotifier.fireTestFailure(failure);
}

public void testAssumptionFailure(Failure failure) {
runNotifier.fireTestAssumptionFailed(failure);
}

public void testIgnored(Description description) throws Exception {
runNotifier.fireTestIgnored(description);
}
};
}

protected Config.Builder createConfig() throws IOException {
Config.Builder configBuilder = new Config.Builder();
final Logger logger = new ConsoleLogger(true);
configBuilder.logger(logger);

RoboVMResolver roboVMResolver = new RoboVMResolver();
roboVMResolver.setLogger(new org.robovm.maven.resolver.Logger() {
public void info(String logLine) {
logger.info(logLine);
}

public void debug(String logLine) {
logger.debug(logLine);
}
});

Config.Home home = null;
try {
home = Config.Home.find();
} catch (Throwable t) {
}
if (home == null || !home.isDev()) {
home = new Config.Home(roboVMResolver.resolveAndUnpackRoboVMDistArtifact(Version.getVersion()));
}
configBuilder.home(home);
if (home.isDev()) {
configBuilder.useDebugLibs(Boolean.getBoolean("robovm.useDebugLibs"));
configBuilder.dumpIntermediates(true);
}

File basedir = new File(System.getProperty("user.dir"));
if (System.getProperties().containsKey(PROP_PROPERTIES_FILE)) {
File propertiesFile = new File(System.getProperty(PROP_PROPERTIES_FILE));
if (!propertiesFile.exists()) {
throw new FileNotFoundException("Failed to find specified "
+ PROP_PROPERTIES_FILE + ": " + propertiesFile.getAbsolutePath());
}
logger.debug("Loading RoboVM config properties from "
+ propertiesFile.getAbsolutePath());
configBuilder.addProperties(propertiesFile);
} else {
configBuilder.readProjectProperties(basedir, true);
}

if (System.getProperties().containsKey(PROP_CONFIG_FILE)) {
File configFile = new File(System.getProperty(PROP_CONFIG_FILE));
if (!configFile.exists()) {
throw new FileNotFoundException("Failed to find specified "
+ PROP_CONFIG_FILE + ": " + configFile.getAbsolutePath());
}
logger.debug("Loading RoboVM config from " + configFile.getAbsolutePath());
configBuilder.read(configFile);
} else {
configBuilder.readProjectConfig(basedir, true);
}

if (System.getProperty(PROP_OS) != null) {
configBuilder.os(OS.valueOf(System.getProperty(PROP_OS)));
}
if (System.getProperty(PROP_ARCH) != null) {
configBuilder.arch(Arch.valueOf(System.getProperty(PROP_ARCH)));
}
if (Boolean.getBoolean(PROP_IOS_SKIP_SIGNING)) {
configBuilder.iosSkipSigning(true);
} else {
if (System.getProperty(PROP_IOS_SIGNING_IDENTITY) != null) {
String iosSignIdentity = System.getProperty(PROP_IOS_SIGNING_IDENTITY);
logger.debug("Using explicit iOS Signing identity: " + iosSignIdentity);
configBuilder.iosSignIdentity(SigningIdentity.find(
SigningIdentity.list(), iosSignIdentity));
}
if (System.getProperty(PROP_IOS_PROVISIONING_PROFILE) != null) {
String iosProvisioningProfile = System.getProperty(PROP_IOS_PROVISIONING_PROFILE);
logger.debug("Using explicit iOS provisioning profile: " + iosProvisioningProfile);
configBuilder.iosProvisioningProfile(ProvisioningProfile.find(
ProvisioningProfile.list(), iosProvisioningProfile));
}
}

for (String clazz : getNonTestClasses(new File(System.getProperty("user.dir") + File.separator + "target"
+ File.separator + "classes"))) {
configBuilder.addForceLinkClass(clazz);
}

configBuilder.addClasspathEntry(roboVMResolver
.resolveArtifact("org.robovm:robovm-objc:" + Version.getVersion()).asFile());
configBuilder.addClasspathEntry(new File(System.getProperty("user.dir") + File.separator + "target"
+ File.separator + "classes"));
configBuilder.addClasspathEntry(new File(System.getProperty("user.dir") + File.separator + "target"
+ File.separator + "test-classes"));


for (String p : System.getProperty("java.class.path").split(File.pathSeparator)) {
if (!p.contains("jdk") && !p.contains("robovm-compiler")) {
configBuilder.addClasspathEntry(new File(p));
}
}

configBuilder.addForceLinkClass(getName());
configBuilder.skipInstall(true);

return configBuilder;
}

private List<String> getNonTestClasses(File file) {
List<String> returnList = new ArrayList<>();
for (File dir : FileUtils.listFilesAndDirs(file, FalseFileFilter.INSTANCE, DirectoryFileFilter.DIRECTORY)) {
for (File file1 : dir.listFiles()) {
if (file1.getName().endsWith("class")) {
String[] pkg = dir.getAbsoluteFile().toString().split("classes/");
if (pkg.length > 1) {
returnList.add(pkg[1].replaceAll(String.valueOf(File.separatorChar), ".") + ".*");
}
break;
}
}

}
return returnList;
}

}
Loading