简体   繁体   中英

I am new to Selenium, but why is Maven skipping over my test and telling me the build was successful?

I been trying for the past 3 hours to try to get a single MyTest.java file to run. But no matter what I try, Maven seems to want to skip over my test and tell me BUILD SUCCESS . But I wasn't try to build anything. I was just trying to "Maven Test".

When I run MyTest.java by itself, it runs fine , but for some reason Maven wants to skip over it.

This is what I wrote.

package SeleniumT;

import org.testng.annotations.Test;

public class MyTest {

    @Test
    public void login() {
        //return "sample";
        System.out.println("########This is my first Maven project#######");
    }
}

My console output keeps saying there is nothing to compile, which makes no sense.

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-demo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.287 s
[INFO] Finished at: 2018-02-15T17:27:11-05:00
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------

My POM file has all the dependencies required to run this. I don't have Maven Surefire plugin I think, but that shouldn't cause a issue, I am assuming.

<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>
  <groupId>SeleniumT</groupId>
  <artifactId>maven-demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
  <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.43.0</version>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.8</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

What could be causing Maven to skip my simple Java test?

Maven文件夹结构

First of all, I noticed your java file is called apptest.java but your actual public class definition is named MyTest . Rename the java file to MyTest.java . Such a difference usually raises compilations error, what makes me believe you Eclipse project is not set to Build automatically .

If that's not the problem, maybe the Maven Test option you have invoked is not invoking test goal. Concerning the "Nothing to compile" message, I'd suggest you to always perform a clean so maven get rid of previously compiled classes and build it from scratch again.

Summing up: right click on the project > Run As > Maven Build... > Type clean test on the Goals field > Click Run . Check if something has changed.

If you succed, the next time you need to run this again, this run configuration you've just created will be already listed on the Run As > Maven build menu.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM