Issue Type: Bug
I have a Spring boot project that I'm trying to test with this extension.
I'm using Java 8 and Junit.
It's a maven project.
The test runner claim it cannot find the main class.
[INFO] Listening for transport dt_socket at address: 38349
[ERROR] Error: Could not find or load main class com.microsoft.java.test.runner.Launcher
.
[INFO] Listening for transport dt_socket at address: 37621
[ERROR] Error: Could not find or load main class com.microsoft.java.test.runner.Launcher.
[ERROR]
.
[INFO] Listening for transport dt_socket at address: 38995
[ERROR] Error: Could not find or load main class com.microsoft.java.test.runner.Launcher
here is my testing code
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ElementRestControllerTest {
@LocalServerPort
private int port;
private String url;
private RestTemplate restTemplate;
private ObjectMapper jsonMapper;
@Rule
public ExpectedException thrown = ExpectedException.none();
private ElementTO dummyElement;
private ElementTO dummy2;
private ElementTO dummy3;
@PostConstruct
public void init() {
this.restTemplate = new RestTemplate();
this.url = "http://localhost:" + port;
System.err.println(this.url);
// Jackson init
this.jsonMapper = new ObjectMapper();
}
@Before
public void setup() {
Map<String, Object> att = new HashMap<>();
att.put("attribute1", new HashMap());
this.dummyElement = new ElementTO("sheena", "123", new Location(13.0, 25.0), "Pen", new Date("20/11/18"),
new Date("19/11/19"), "tool", att, "sheena", "[email protected]");
this.dummy2 = new ElementTO("playground", "456", this.dummyElement.getLocation(), this.dummyElement.getName(),
this.dummyElement.getCreationDate(), this.dummyElement.getExpirationDate(), this.dummyElement.getType(),
this.dummyElement.getAttributes(), this.dummyElement.getCreatorPlayground(),
this.dummyElement.getCreatorEmail());
this.dummy3 = new ElementTO("playground", "789", new Location(4.0, 24.9), this.dummyElement.getName(),
this.dummyElement.getCreationDate(), this.dummyElement.getExpirationDate(), this.dummyElement.getType(),
this.dummyElement.getAttributes(), this.dummyElement.getCreatorPlayground(),
this.dummyElement.getCreatorEmail());
}
@Test
public void addNewElementSuccessfully() {
String targetUrl = String.format("%s/playground/elements/%s/%s", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail());
ElementTO actualElement = this.restTemplate.postForObject(targetUrl, this.dummyElement, ElementTO.class);
assertThat(actualElement).isNotNull().isEqualTo(this.dummyElement);
}
@Test
public void updateElementSuccessfully() {
String postTargetUrl = String.format("%s/playground/elements/%s/%s", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail());
// Given
this.dummyElement.setLocation(new Location(26.0, 24.9));
this.restTemplate.postForObject(postTargetUrl, this.dummyElement, ElementTO.class);
// When
ElementEntity elementEntity = this.dummyElement.toEntity();
String putTargetUrl = String.format("%s/playground/elements/%s/%s/%s/%s", this.url,
elementEntity.getCreatorPlayground(), elementEntity.getCreatorEmail(), elementEntity.getPlayground(),
elementEntity.getId());
this.restTemplate.put(putTargetUrl, this.dummyElement);
// Then
assertThat(elementEntity.getLocation()).isEqualTo(new Location(26.0, 24.9));
}
@Test
public void getElementByItsIDSuccessfully() {
String postTargetUrl = String.format("%s/playground/elements/%s/%s", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail());
// Given
this.restTemplate.postForObject(postTargetUrl, this.dummyElement, ElementTO.class);
// When
String getTargetUrl = String.format("%s/playground/elements/%s/%s/%s/%s", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail(),
this.dummyElement.getPlayground(), this.dummyElement.getId());
ElementTO actualElementTO = this.restTemplate.getForObject(getTargetUrl, ElementTO.class);
// Then
assertThat(actualElementTO).isEqualTo(this.dummyElement);
}
@Test
public void getElementByItsIDWhenIDDoesNotExistShouldHttpServerErrorException() throws HttpServerErrorException {
thrown.expect(HttpServerErrorException.class);
thrown.expectMessage("500 null");
// When
String getTargetUrl = String.format("%s/playground/elements/%s/%s/%s/%s", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail(),
this.dummyElement.getPlayground(), 1);
this.restTemplate.getForObject(getTargetUrl, ElementTO.class);
}
@Test
public void getAllElementsSuccesfully() {
String postTargetUrl = String.format("%s/playground/elements/%s/%s", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail());
// Given
this.restTemplate.postForObject(postTargetUrl, this.dummyElement, ElementTO.class);
this.restTemplate.postForObject(postTargetUrl, this.dummy2, ElementTO.class);
// When
String getAllUrl = String.format("%s/playground/elements/%s/%s/all", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail());
ElementTO[] elements = this.restTemplate.getForObject(getAllUrl, ElementTO[].class);
// Then
ElementTO[] expected = { this.dummyElement, dummy2 };
assertThat(elements).isNotNull().hasSize(2).isEqualTo(expected);
}
@Test
public void getElementByCoordinatesShouldReturnMatch() {
String postTargetUrl = String.format("%s/playground/elements/%s/%s", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail());
// Given
this.restTemplate.postForObject(postTargetUrl, this.dummyElement, ElementTO.class);
this.restTemplate.postForObject(postTargetUrl, this.dummy3, ElementTO.class);
// When
///playground/elements/{userPlayground}/{email}/near/{x}/{y}/{distance}
String getAllUrl = String.format("%s/playground/elements/%s/%s/near/%d/%d/%d", this.url,
this.dummyElement.getCreatorPlayground(), this.dummyElement.getCreatorEmail(), 10, 20, 5);
assertThat(getAllUrl).isEqualTo(this.url + "/playground/elements/sheena/[email protected]/near/10/20/5");
ElementTO[] elements = this.restTemplate.getForObject(getAllUrl, ElementTO[].class);
assertThat(elements).containsOnly(this.dummyElement);
}
}
Extension version: 0.11.0
VS Code version: Code 1.29.1 (bc24f98b5f70467bc689abf41cc5550ca637088e, 2018-11-15T19:07:43.495Z)
OS version: Linux x64 4.15.0-39-generic
System Info
|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz (4 x 1728)|
|GPU Status|2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: unavailable_software
video_encode: unavailable_software
webgl: enabled
webgl2: enabled|
|Load (avg)|1, 1, 1|
|Memory (System)|7.70GB (1.33GB free)|
|Process Argv|--unity-launch|
|Screen Reader|no|
|VM|0%|
Seems you meet this issue when debugging the test code.
Is the functionality works correctly when just triggering Run Test?
@jdneo thanks for the quick reply. It also happen when i try to use Run Test.
the only way i can run the tests if via the maven plugin which triggers the command mvnw test
Iv'e tried now running Run Test on a windows machine and it got stuck on running tests ( i will further check on this). Though i can see in the logs that it ran part of the tests
Hmm, looks wired. I haven't met this issue before.
Will it help if you do the following things?
$HOME/.vscode/extensions/vscjava.vscode-java-test-*same here. plugin version 0.11.1
code version 1.29.1-1542309157
Java 8, JUnit5, maven
Hmm, looks wired. I haven't met this issue before.
Will it help if you do the following things?
- Uninstall the extension in VS Code
- Remove the extension files under:
$HOME/.vscode/extensions/vscjava.vscode-java-test-*- Install the extension again
On the Ubuntu machine, reinstalling the extension did not help. I also updated the extension to 0.11.1, same thing.
On the windows machine, I ran a simple test that tests a POJO class, the test runner ran the test and showed the results. But when i ran the spring test of the code attached below, the test runner hanged with the message Running tests, though i can see in the logs that the tests ran and completed and even passed. here are the logs
[INFO] @@<TestRunner-{"name":"testFinished", "attributes":{"name":"com.sheena.playground.api.ElementRestControllerTest#getElementByItsIDSuccessfully", "duration":"36"}}-TestRunner>
@@<TestRunner-{"name":"testSuiteFinished", "attributes":{"name":"com.sheena.playground.api.ElementRestControllerTest"}}-TestRunner>
@@<TestRunner-{"name":"testSummary", "attributes":{"message":"Total tests run: 7, Failures: 0, Skips: 0"}}-TestRunner>
@ugurlu @amitlevy21 Is it possible to share a sample project to me to repro the issue?
I tried but not able to repro it on my side
@jdneo its a private repo, i can share a snapshot though.
Test-Runner-Application.zip
@ugurlu Is your environment also Linux?
ubuntu 18.04
interesting note.
after commenting out spring-boot-maven-plugin, test works.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
interesting note.
after commenting out spring-boot-maven-plugin, test works.<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
did not worked for me, i'm still getting the same error.
Oddly enough, the entity test i managed to run before, does not run now even after uncommenting plugin
I am having the same issue running tests since last week. Get this error in output panel [ERROR] Error: Could not find or load main class com.microsoft.java.test.runner.Launcher. Running mvn test runs the tests as normal.
I have uninstalled the extension ,reloaded vscode, then reinstalled.
java test runner 0.11.1
vscode 1.29.1
java 1.8.0_181
junit 4.12
ubuntu 8.10
P.S I am not using sprint boot in my project
Ok did some playing around after I saw that the other two people were using spring boot. I tried another project that was a basic java project and the tests worked. Then I started added dependencies from the other project that didn't work and had an issue as soon as I added kumuluzee-bom and the micro profile 1.2
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-bom</artifactId>
<version>2.53</version>
<type>pom</type>
<scope>import</scope>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-microProfile-1.2</artifactId>
<version>2.5.3</version>
I have not updated these dependenies to a new version for a while so don't think the issue is with them.
Confirming, I'm experiencing this issue on Ubuntu 16.04
Exact same project works on Mojave 10.14.1 and Windows 10 (not sure of the version, ran by a colleague).
VS Code 1.29.1
I do not have the kumuluz dependency that zerosandones mentioned.
After more playing around I updated to openjdk 11 and the tests now run correctly.
Also I update my system which updated my version of java to 1.8.0_191 and the tests now work using that version as well.
Confirming @zerosandones note, upgrading to 1.8.0_191 fixes the problem for me. Thank-you! :+1:
i've update my jre to 1.8.0_191 with the command sudo apt-get install default-jre
here is my java -version output -> openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-0ubuntu0.16.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
I can run the tests, but the ElementRestControllerTest test I'm trying to run, hangs the extension with the message Running tests although I'm seeing the logs i provided before:
[INFO] @@<TestRunner-{"name":"testFinished", "attributes":{"name":"com.sheena.playground.api.ElementRestControllerTest#getElementByItsIDSuccessfully", "duration":"36"}}-TestRunner>
@@<TestRunner-{"name":"testSuiteFinished", "attributes":{"name":"com.sheena.playground.api.ElementRestControllerTest"}}-TestRunner>
@@<TestRunner-{"name":"testSummary", "attributes":{"message":"Total tests run: 7, Failures: 0, Skips: 0"}}-TestRunner>
@jdneo should i open a different issue and close this one?
Edit:
i think my issue can relate to #482
Looks like upgrade java version to the latest can solve the problem.
@amitlevy21 Yes there is a same issue as yours. Let's track your problem in #482
Thanks.
Debian 9 openjdk fails, I installed Amazon Corretto and it is working now:
Do not work:
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
Works:
openjdk version "1.8.0_202"
OpenJDK Runtime Environment Corretto-8.202.08.2 (build 1.8.0_202-b08)
OpenJDK 64-Bit Server VM Corretto-8.202.08.2 (build 25.202-b08, mixed mode)
It seems to be an issue with the jdk version.
Most helpful comment
After more playing around I updated to openjdk 11 and the tests now run correctly.
Also I update my system which updated my version of java to 1.8.0_191 and the tests now work using that version as well.